日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS开发(第三方使用)——极光推送SDK接入

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS开发(第三方使用)——极光推送SDK接入 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • pod ‘JPush’
  • 添加Framework
    CFNetwork.framework
    CoreFoundation.framework
    CoreTelephony.framework
    SystemConfiguration.framework
    CoreGraphics.framework
    Foundation.framework
    UIKit.framework
    Security.framework
    libz.tbd (Xcode7以下版本是libz.dylib)
    AdSupport.framework (獲取IDFA需要;如果不使用IDFA,請不要添加)
    UserNotifications.framework (Xcode8及以上)
    libresolv.tbd (JPush 2.2.0及以上版本需要, Xcode7以下版本是libresolv.dylib)

  • AppDelegate.m代碼
  • //推送 #import <JPUSHService.h> // iOS10注冊APNs所需頭文件 #ifdef NSFoundationVersionNumber_iOS_9_x_Max #import <UserNotifications/UserNotifications.h> #endif //JPUSHRegisterDelegate代理 @interface AppDelegate ()<JPUSHRegisterDelegate>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//推送[self registerRemoteNotification];//測試if([jgAPNSForProduction isEqualToString:@"0"]){[JPUSHService setupWithOption:launchOptions appKey:jgAppKeychannel:@"App Store"apsForProduction:NOadvertisingIdentifier:nil];}else{//api打包[JPUSHService setupWithOption:launchOptions appKey:jgAppKeychannel:@"App Store"apsForProduction:YESadvertisingIdentifier:nil];}//獲取registrationID通知[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getRegistrationID:) name:kJPFNetworkDidLoginNotification object:nil];//獲取透傳信息通知[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];}//注冊APNS - (void)registerRemoteNotification {if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];} else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {//可以添加自定義categories[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)categories:nil];} else {//categories 必須為nil[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)categories:nil]; }//registrationID與后臺交互使用 -(void)getRegistrationID:(NSNotification *)notification {NSString *registrationID=[JPUSHService registrationID]; // NSLog(@"registrationID=%@",registrationID);//[self sendRegistrationID];//把registrationID傳給后臺 }//透傳(即應用內推送) - (void)networkDidReceiveMessage:(NSNotification *)notification{ // NSLog(@"userinfo=%@",notification.userInfo);//收到推送,自行處理}//token - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {//注冊 DeviceToken[JPUSHService registerDeviceToken:deviceToken]; }//APNS - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {// Required,For systems with less than or equal to iOS6[JPUSHService handleRemoteNotification:userInfo]; }- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {// IOS 7 Support Required[JPUSHService handleRemoteNotification:userInfo];completionHandler(UIBackgroundFetchResultNewData); }#pragma mark- JPUSHRegisterDelegate// iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {// RequiredNSDictionary * userInfo = notification.request.content.userInfo;if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}completionHandler(UNNotificationPresentationOptionAlert); // 需要執行這個方法,選擇是否提醒用戶,有Badge、Sound、Alert三種類型可以選擇設置 }// iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {// RequiredNSDictionary * userInfo = response.notification.request.content.userInfo;if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}completionHandler(); // 系統要求執行這個方法 }

    總結

    以上是生活随笔為你收集整理的iOS开发(第三方使用)——极光推送SDK接入的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。