欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS10 遠(yuǎn)程推送適配詳細(xì)介紹

 更新時(shí)間:2016年12月24日 11:45:57   作者:ParadiseMayCry  
這篇文章主要介紹了IOS10 遠(yuǎn)程推送適配詳細(xì)介紹的相關(guān)資料,iOS10推送新增了UserNotifications Framework,這里主要介紹如何實(shí)現(xiàn)遠(yuǎn)程推送,需要的朋友可以參考下

IOS10 遠(yuǎn)程推送適配

iOS10推送新增了UserNotifications Framework,使用起來其實(shí)很簡單。

建議看看極光推送的Demo,里面寫的更詳細(xì)。

只是在iOS10以上系統(tǒng)上點(diǎn)擊通知欄,回調(diào)方法不再走原來的這兩個(gè)方法

- (void)application:(UIApplication *)application 
didReceiveRemoteNotification:(NSDictionary *)userInfo {}
- (void)application:(UIApplication *)application
 didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {}

而是在前臺的時(shí)候回調(diào)

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
willPresentNotification:(UNNotification *)notification 
withCompletionHandler:(void (^)
(UNNotificationPresentationOptions))completionHandler

從后臺進(jìn)入的時(shí)候回調(diào)

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
 didReceiveNotificationResponse:(UNNotificationResponse *)response 
withCompletionHandler:(void (^)())completionHandler

直接說怎么用吧:

1,導(dǎo)入頭文件

#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif

2,注冊通知

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中

if (iOS10) {
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;
  [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge 
| UNAuthorizationOptionSound | UNAuthorizationOptionAlert) 
completionHandler:^(BOOL granted, NSError * _Nullable error) {
   if (!error) {
    NSLog(@"succeeded!");
   }
  }];
 } else if (iOS8_9){//iOS8-iOS9
  UIUserNotificationSettings *settings = [UIUserNotificationSettings 
settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert 
| UIUserNotificationTypeSound) categories:nil];
  [application registerUserNotificationSettings:settings];
  [application registerForRemoteNotifications];
 } else {//iOS8以下
  [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge
 | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
 }

3,回調(diào)方法中,獲取通知數(shù)據(jù)

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
didReceiveNotificationResponse:(UNNotificationResponse *)response 
withCompletionHandler:(void (^)())completionHandler {
 NSDictionary *userInfo = response.notification.request.content.userInfo;
   //消息處理
 if([request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  //判斷為遠(yuǎn)程推送
 }else {
  // 判斷為本地通知 
 }
}

4,對于本地通知沒有什么變化依然會回調(diào)

-(void)application:(UIApplication *)application 
didReceiveLocalNotification:(UILocalNotification *)notification

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論