iOS极光推送完整流程
第一步 先在开发者账号创建app id,即创建应用程序ID
详细步骤:
1、登陆苹果开发者网站进入开发者账户。

从开发者账户页面左侧入口进入“Certificates, IDs & Profiles” 页面。

2、创建 App ID,填写 App ID 的 Name 和 Bundle ID( 注: 此处需要指定具体的 Bundle ID 不要使用通配符)。


3、为 App 开启 Push Notification 功能。如果是已经创建的 App ID 也可以通过设置开启 Push Notification 功能。

4、填写好以上属性后,点击 “Continue”,确认 AppId 属性的正确性,点击 “Register”,注册 AppId 成功。
第二步 配置证书,包括开发证书和生产证书两个证书
简述极光推送证书的基本生成流程,两者都为导出的p12文件

开发证书的详细步骤:
1、开发证书的生成(注意选择的Development)。

开发证书生成-01
2、点击continue,来到选择App ID界面。

开发证书生成-02
3、说明让上传自己的CSR文件,continue...

开发证书生成-03
4、上传请求生成的CSR文件,continue...

开发证书生成-04
5、打开系统自带的 “钥匙串访问” 创建 Certificate Signing Request。如下图操作:

开发证书生成-05
6、填写“用户邮箱”和“常用名称” ,并选择“存储到磁盘”,证书文件后缀为.certSigningRequest 。

开发证书生成-06
7、回到浏览器中 CSR 上传页面,上传刚刚生成的后缀为 .certSigningRequest 的文件。

开发证书生成-07
8、生成证书成功后,点击 “Download” 按钮把证书下载下来,是后缀为 .cer 的文件(第一个为“Download”得到的生产开发证书,第二个为“Download”得到的开发证书)。

开发证书生成-08
9、双击证书后,会在“KeychainAccess”中打开,选择左侧“钥匙串”列表中“登录”,以及“种类”列表中“我的证书”,找到刚才下载的证书,并导出为 .p12 文件。如下图:

开发证书生成-09/1

开发证书生成-09/2
10、最后得到导出的证书(第二个)

开发证书生成-09/3
生产证书的详细步骤:
1、注意这里的选择方式和开发证书有略微的区别,选择Production那一项就好 。

生产证书生成-01
2、以下的步骤略去,和开发的一样,到最后下载一下文件,得到下面图的两个文件,双击在钥匙串访问中可见。

生产证书生成-02
3、生产和开发cer文件

生产证书生成-03
4、分别导出的开发证书和生产证书到桌面上(双击证书后,会在“KeychainAccess”中打开,选择左侧“钥匙串”列表中“登录”,以及“种类”列表中“我的证书”,找到刚才下载的证书,并导出为 .p12 文件)。如下图:

生产证书生成-04

生产证书生成-05
第三步 把导出的开发证书和生产证书分别上传到极光平台
1、在极光控制台上,进入你应用的应用设置中 iOS 的鉴权方式选择 “证书”,上传刚才导出的 .p12 证书。极光会在后台为你的应用进行鉴权。

上传到极光平台-01
第四步 集成极光推送SDK,配置工程
1、导入SDK
选择1:Cocoapods导入
通过Cocoapods下载地址:
pod 'JPush'
如果需要安装指定版本则使用以下方式(以3.0.2版本为例):
pod 'JPush', '3.0.2'
选择2:手动导入
在极光官网下载最新SDK,将SDK包解压,在Xcode中选择“Add files to 'Your project name'...”,将解压后的lib子文件夹(包含JPUSHService.h、jpush-ios-x.x.x.a、jcore-ios-x.x.x.a)添加到你的工程目录中。
添加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)(注意:
如果集成JPush 3.0.1及以上版本, 且同时集成极光其他SDK(如:JMessage 3.0.0及以上版本) 1. Cocoapods导入,建议都更新为线上最新版本,来避免Jcore版本不一致导致的冲突。 2. 手动导入,在工程中只需保留一个最新版本的jcore-ios-x.x.x.a静态库文件。)

导入SDK

导入依赖库
3090071-8c949b2daaa8f044.png
Build Settings
如果你的工程需要支持小于7.0的iOS系统,请到Build Settings 关闭 bitCode 选项,否则将无法正常编译通过。
设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths,比如SDK文件夹(默认为lib)与工程文件在同一级目录下,则都设置为"$(SRCROOT)/{静态库所在文件夹名称}"即可。
Capabilities
如使用Xcode8及以上环境开发,请开启Application Target的Capabilities->Push Notifications选项,如图:

允许Xcode7支持Http传输方法
如果您使用的是2.1.9及以上的版本则不需要配置此步骤 如果用的是Xcode7或更新版本,需要在App项目的plist手动配置下key和值以支持http传输:
选择1:根据域名配置
在项目的info.plist中添加一个Key:NSAppTransportSecurity,类型为字典类型。
然后给它添加一个NSExceptionDomains,类型为字典类型;
把需要的支持的域添加給NSExceptionDomains。其中jpush.cn作为Key,类型为字典类型。
每个域下面需要设置2个属性:NSIncludesSubdomains、NSExceptionAllowsInsecureHTTPLoads。 两个属性均为Boolean类型,值分别为YES、YES。
如图:

选择2:全局配置

环境配置
第五步 工程代码部分
1、 进入项目的appdelegate里面,首先导入头文件和遵循代理
import "AppDelegate.h"
import "JPUSHService.h"
ifdef NSFoundationVersionNumber_iOS_9_x_Max
import
@interface AppDelegate ()
2、 在didFinishLaunchingWithOptions方法中配置
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self jpushInitWith:launchOptions];
}
-(void)jpushInitWith:(NSDictionary)launchOptions
{
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
//生成idfa 字段
NSString
advertisingId=[SimulateIDFA createSimulateIDFA];
DDLog(@"----ifda----%@",advertisingId);
if (advertisingId) {
[[NSUserDefaults standardUserDefaults] setObject:advertisingId forKey:@"advertisingId"];
}
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
[defaultCenter addObserver:self selector:@selector(networkDidLogin:) name:kJPFNetworkDidLoginNotification object:nil];
[JPUSHService setupWithOption:launchOptions appKey:appKey
channel:channel
apsForProduction:isProduction
advertisingIdentifier:advertisingId];
//设置红色角标
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService setBadge:0];
}
3、 实现通知和协议方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"showRedBadge" object:nil userInfo:userInfo];
// Required, iOS 7 Support[JPUSHService handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); } - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { DDLog(@"----userinfo---%@----",userInfo);// Required,For systems with less than or equal to iOS6[JPUSHService handleRemoteNotification:userInfo]; } - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {//OptionalNSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); } - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { [JPUSHService registerDeviceToken:deviceToken]; }#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:[UNPushNotificationTriggerclass]]) { [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: [UNPushNotificationTriggerclass]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler();// 系统要求执行这个方法}
4、pragma mark 通知
- (void)networkDidReceiveMessage:(NSNotification*)notification {NSDictionary* userInfo = [notification userInfo];// NSString *content = [userInfo valueForKey:@"content"];// NSDictionary *extras = [userInfo valueForKey:@"extras"];// NSString *customizeField1 = [extras valueForKey:@"customizeField1"]; //服务端传递的Extras附加字段,key是自己定义的DDLog(@"----userInfo---%@",userInfo);//发送通知[[NSNotificationCenterdefaultCenter] postNotificationName:@"showRedBadge"object:niluserInfo:userInfo];} - (void)networkDidLogin:(NSNotification*)notification {NSLog(@"已登录");if([JPUSHService registrationID]) {//下面是我拿到registeID,发送给服务器的代码,可以根据你需求来处理NSString*registerid = [JPUSHService registrationID];NSLog(@"APPDelegate开始上传rgeisterID---%@",registerid);if(registerid) { [[NSUserDefaultsstandardUserDefaults] setObject:registerid forKey:@"registerid"]; } } }
第六步 推送测试

推送测试
相关文档可点击以下链接:
1、https://blog.csdn.net/zhanglizhi111/article/details/79507549
2、https://blog.csdn.net/lqq200912408/article/details/54376208
3、https://blog.csdn.net/cc1991_/article/details/78782946