【SDK】极光推送
官方文檔
iOS SDK 集成指南
cocoapods集成
# 極光推送pod 'JPush'添加頭文件
// 引入 JPush 功能所需頭文件 #import "JPUSHService.h" // iOS10 注冊 APNs 所需頭文件 #ifdef NSFoundationVersionNumber_iOS_9_x_Max #import <UserNotifications/UserNotifications.h> #endif初始化
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions {JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];if (@available(iOS 12.0, *)) {entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;} else {entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;}[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];// 啟動SDK[JPUSHService setupWithOption:launchOptionsappKey:JPUSH_APPKEYchannel:@"App Store"apsForProduction:1advertisingIdentifier:nil];// release版本關閉Log打印[JPUSHService setLogOFF];return YES; }apsForProduction
1.3.1 版本新增,用于標識當前應用所使用的 APNs 證書環境。
0(默認值)表示采用的是開發證書,1 表示采用生產證書發布應用。
注:此字段的值要與 Build Settings的Code Signing 配置的證書環境一致。
AppDelegate代理方法
// 注冊 APNs 成功并上報 DeviceToken - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {/// Required - 注冊 DeviceToken[JPUSHService registerDeviceToken:deviceToken]; }// 注冊 APNs 失敗接口 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {//OptionalLRLog(@"注冊token失敗:*****did Fail To Register For Remote Notifications With Error: %@", error); }// 收到推送通知 iOS 10 以后不需要調用該方法,極光集成了UNUserNotification - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {[JPUSHService handleRemoteNotification:userInfo];completionHandler(UIBackgroundFetchResultNewData); }JPUSHRegisterDelegate
// App在前臺運行,收到推送消息 - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger options))completionHandler {if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}// 彈出通知框,不執行這段代碼,不會在通知欄彈出提示框completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);}// 點擊通知欄推送消息 - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}completionHandler(); } // iOS 12 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification {if (notification && [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {// 從通知界面直接進入應用}else{// 從通知設置界面進入應用} } // 監測通知授權狀態返回的結果 - (void)jpushNotificationAuthorization:(JPAuthorizationStatus)status withInfo:(NSDictionary *)info {}App在后臺時收到推送通知自動在通知欄彈窗提示。
Api
設置別名(登錄成功調用,用戶id作為別名)
別名不支持中劃線,恰巧我們的數據格式包含中劃線,做了字符串轉換。
有效的別名組成:字母(區分大小寫)、數字、下劃線、漢字、特殊字符@!#$&*+=.|
刪除別名(退出登錄,不再接收推送)
[JPUSHService deleteAlias:nil seq:0];設置服務器端角標
[JPUSHService setBadge:0];設置本地角標
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];總結
- 上一篇: linux tar解压bin文件,lin
- 下一篇: 359B. Permutation