iOS10推送通知適配
iOS10推送新增了UserNotifications Framework,使用起來其實很簡單。
只是在iOS10以上系統上點選通知欄,回撥方法不再走原來的這兩個方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler {
}
而是在前臺的時候回撥
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler
從後臺進入的時候回撥
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
直接說怎麼用吧:
1,匯入標頭檔案
#import
2,註冊通知
#defineIOS8 ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0 && [[UIDevice currentDevice].systemVersion doubleValue] < 9.0)#defineIOS8_10 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 && [[UIDevice currentDevice].systemVersion doubleValue] < 10.0)#defineIOS10 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0)
- (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!"); } }]; }elseif(IOS8_10){//iOS8-iOS10 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert |UIUserNotificationTypeSound) categories:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; }else{//iOS8以下 [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert |UIRemoteNotificationTypeSound];
}
3,回撥方法中,獲取通知資料(前臺類似不做說明)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
NSDictionary*userInfo =response.notification.request.content.userInfo;
//訊息處理
}
4,對於本地通知沒有什麼變化依然會回撥
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
相關文章
- iOS10推送適配完整說明iOS
- [iOS]適配iOS10問題iOS
- fir.im Weekly - 關於 iOS10 適配、開發、推送的一切iOS
- iOS10 CAAnimationDelegate 的簡單適配iOS
- Widget的簡單應用並適配iOS10iOS
- iOS開發 適配iOS10以及Xcode8iOSXCode
- iOS10 再談 CAAnimationDelegate 相關協議的適配iOS協議
- iOS12、iOS11、iOS10、iOS9常見適配iOS
- iOS 推送通知及推送擴充套件iOS套件
- iOS10 推送必看 UNNotificationContentExtensioniOS
- iOS本地通知(推送)iOS
- iOS10適配 完美解決相機、相簿等許可權的使用iOS
- Android適配: 拉伸適配的缺點Android
- flutter 螢幕尺寸適配 字型大小適配Flutter
- 適配 iOS 10,極光推送使用者要做這 6 處更改iOS
- iOS10註冊推送的細節iOS
- iOS13 即將到來,iOS 推送 DeviceToken 適配步驟詳解iOSdev
- ios推送:本地通知UILocalNotificationiOSUI
- Android適配Android
- iOS 11適配iOS
- https適配HTTP
- 適配iphone XiPhone
- iOS12中推送通知新特性iOS
- Hybird推送通知然後跳轉appAPP
- android螢幕適配三:通過畫素密度適配Android
- Android螢幕適配(理論適配100%機型)Android
- Swift3.0 已出坑-適配 iOS10,專案遷移 Swift3.0 問題總結SwiftiOS
- Flutter螢幕適配Flutter
- Rem 等比適配始末REM
- Flutter深色模式適配Flutter模式
- h5適配H5
- rem 適配佈局REM
- Viewport 等比適配始末View
- iOS11 適配iOS
- iphone 適配的sdkiPhone
- UIWebView 適配螢幕UIWebView
- iphoneX適配iPhone
- pc大屏適配