iOS开发(第三方使用)——极光推送SDK接入
2016-09-06 17:18
615 查看
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)
![](https://img-blog.csdn.net/20161129105855383)
AppDelegate.m代码
添加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:jgAppKey channel:@"App Store" apsForProduction:NO advertisingIdentifier:nil]; }else{//api打包 [JPUSHService setupWithOption:launchOptions appKey:jgAppKey channel:@"App Store" apsForProduction:YES advertisingIdentifier: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 { // Required NSDictionary * 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 { // Required NSDictionary * userInfo = response.notification.request.content.userInfo; if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler(); // 系统要求执行这个方法 }
相关文章推荐
- iOS开发(第三方使用)——讯飞语音SDK接入
- iOS开发-极光推送SDK使用笔记
- iOS开发——iOS10升级极光推送SDK、友盟分享SDK
- ios开发--极光推送(jpush)遇坑1---导入sdk
- [iOS APNs极光推送] APNs证书+极光推送+简单使用+仅开发环境
- iOS极光推送SDK的使用流程
- IOS开发使用极光平台进行远程推送
- iOS极光推送SDK的使用流程
- Android开发中的第三方支付SDK的接入与使用(支付宝+微信支付+银联)
- [iOS]极光推送JPushSDK开发--准备篇
- [置顶] Android开发之第三方推送JPush极光推送知识点详解 学会集成第三方SDK推送
- 极光推送JPush,JPush-iOS-SDK-1.8-2.1(IOS8),图文解说,开发模式
- 使用cmcc.in官方提供的sdk开发第三方接入应用
- Unity3d与iOS交互开发——接入平台SDK必备技能
- api工程IOS学习:在IOS开发中使用GoogleMaps SDK
- (转)在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送
- iOS开发之友盟统计SDK的使用
- iOS开发 使用Cocoapods管理第三方类库
- iOS开发之Sqlite 第三方库FMDB的使用
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录