200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > iOS开发(第三方使用)——极光推送SDK接入

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

时间:2021-10-03 21:46:10

相关推荐

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 *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(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(); // 系统要求执行这个方法}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。