일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Magnify Anim
- sha1 convert hashkey
- Android NDK시스템
- embedd
- IMAGE
- so file
- ios
- android log dump
- 인증서 정보 뽑아내기
- IOS10
- ios framework
- v8 engine xcode build
- appbarlayout
- java
- SO 파일
- Status Bar
- 안드로이드
- 공인인증서 정보
- apns
- PageControl
- Push
- apache
- 공인인증서 만료일
- V8 Engine
- apk 다운사이징
- Android
- Google V8 Engine
- FlexiblePageView
- Objective C
- JavaScript Engine
- Today
- Total
caTea 블로그
ios10 push notification 세팅 본문
ios10부터 클라이언트에서 apns 등록요청이 달라졌다 하여 하위호완성을 고려해 10버전일경우 분기처리하였다
APPDELEGATE HEADER
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
--------------------------------------------------------------------------------------------------------------------------
APPDELEGATE.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
.
.
.
.
// APNS 등록 10ver 이상
if([[UIDevice currentDevice] systemVersion].floatValue >= 10){
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if( !error ){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
NSLog( @"Push registration FAILED" );
NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
}
}];
} else { //10ver 미만
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
NSLog(@"Requesting permission for push notifications..."); // iOS 8
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |
UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:settings];
}
}
.
.
.
}
#pragma mark -
#pragma mark Apple Push Notification Handler
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken deviceToken = %@", deviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"\n\n\nFailed to get PUSH notification=%@\n\n\n",error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// 10버전 미만일경우 이곳으로 푸시메세지가 온다 단 앱이 실행중일떄다
}
#pragma mark -
#pragma mark push ios10 ver
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
//10버전 이상일경우 이곳으로 메세지가 온다
completionHandler(UNNotificationPresentationOptionAlert); //푸시 배너를 띄운다.
NSLog(@"userNotificationCenter push data = %@",notification.request.content.userInfo);
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
//앱이 백그라운드로 살아있고 푸시가 올떄 배너로 앱 진입시 이곳으로 들어온다.
NSLog(@"userNotificationCenter Userinfo %@",response.notification.request.content.userInfo);
}
'macos | ios' 카테고리의 다른 글
lipo 명령어 ios simulator, iosphone framework 라이브러리 합치기 (0) | 2017.07.13 |
---|---|
ios http/https 대응 (0) | 2016.10.19 |
ios 10 관련 코드 변경점및 관련정보 (0) | 2016.09.04 |
NSURLSession 간편하게 사용하기 (2) | 2016.09.04 |
디바이스 타입 가져오기 (0) | 2016.07.12 |