视频https://community.jiguang.cn/t/jpush-ios-sdk/4247
1.iOS SDK 概述http://docs.jiguang.cn/jpush/client/iOS/ios_sdk/
APNs通知:
应用退出,后台以及打开状态都能收到APNS———>能够拿到通知的内容等。
如果应用后台或退出,会有系统的APNS提醒。如果应用处于打开状态,则不展示———>不以badge sound alert形式展现。
2.iOS SDK 集成指南http://docs.jiguang.cn/jpush/client/iOS/ios_guide_new/
SDK说明
创建应用(开发环境 生产环境)
配置工程(允许Xcode7支持Http传输方法)
3.iOS SDK 调试指南http://docs.jiguang.cn/jpush/client/iOS/ios_debug_guide/
iOS SDK 调试思维导图
确认证书
开发环境测试
发布环境测试
4.iOS 证书设置指南***********http://docs.jiguang.cn/jpush/client/iOS/ios_cer_guide/
5.iOS 新特性汇总http://docs.jiguang.cn/jpush/client/iOS/ios_new_fetures/
iOS 10 Service Extension—>Xcode没有发现Notification Service Extension这个文件
6.iOS SDK APIhttp://docs.jiguang.cn/jpush/client/iOS/ios_api/
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
//(第一步):注册极光推送
if([[UIDevicecurrentDevice].systemVersionfloatValue] >=10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
JPUSHRegisterEntity* entity = [[JPUSHRegisterEntityalloc]init];
entity.types=UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[JPUSHServiceregisterForRemoteNotificationConfig:entitydelegate:self];
#endif
}elseif([[UIDevicecurrentDevice].systemVersionfloatValue] >=8.0) {
//可以添加自定义categories
[JPUSHServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge|
UIUserNotificationTypeSound|
UIUserNotificationTypeAlert)
categories:nil];
}else{
//categories必须为nil
[JPUSHServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeSound|
UIRemoteNotificationTypeAlert)
categories:nil];
}
//如不需要使用IDFA,advertisingIdentifier可为nil———>>IDFA是什么?
[JPUSHServicesetupWithOption:launchOptionsappKey:JPushSDK_AppKey
channel:nil
apsForProduction:isProduction
advertisingIdentifier:nil];
//(第二步):2.1.9版本新增获取registration id block接口——>>Jpush是以广播的形势发送id,发送成功就回调用block块
[JPUSHServiceregistrationIDCompletionHandler:^(intresCode,NSString*registrationID) {
if(resCode ==0){
NSLog(@"registrationID获取成功:%@",registrationID);
JPushregistrationID= registrationID;
NSLog(@"7777777JPushRegisterID:%@",JPushregistrationID);//测试OK
// 2.存本地
[[NSUserDefaultsstandardUserDefaults]setObject:JPushregistrationIDforKey:JPushID];
[[NSUserDefaultsstandardUserDefaults]synchronize];
// 3.跟新极光token接口
//判断是否登录(已登录:跟新未登录:不做处理)
BOOLisLogin = [MyStringisOnline];
if(!isLogin) {
}else{
//"极光推送token更新"(新增)接口
[selfupdateJPushTokenWith:registrationID];
}
}
else{
NSLog(@"registrationID获取失败,code:%d",resCode);
}
}];
//这个判断是在程序没有运行的情况下收到通知并点击通知时---逻辑-->>跳转物流中心页面
if(launchOptions) {
NSDictionary* remoteNotification = [launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(remoteNotification) {
NSLog(@"推送消息==== %@",remoteNotification);
//跳转物流中心页面(因为发的通知是物流到货通知)
[selfgoToMessageViewController];
}
}
//收到自定消息(通过监听者来监听(纯测试用))
NSNotificationCenter*defaultCenter = [NSNotificationCenterdefaultCenter];
[defaultCenteraddObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
returnYES;
}
#pragma mark--->>(第三步)注册DeviceToke
- (void)application:(UIApplication*)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
/// Required -注册DeviceToken
[JPUSHServiceregisterDeviceToken:deviceToken];
NSLog(@"deviceToken%@",deviceToken);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(nonnullNSError*)error {
NSLog(@"注册远程失败");
}
#pragma mark
#pragma mark---->>(第四步)获取APNs(通知)推送内容(不同系统版本适配不同方法)
- (void)application:(UIApplication*)application
didReceiveRemoteNotification:(NSDictionary*)userInfo {
[JPUSHServicehandleRemoteNotification:userInfo];
NSLog(@"iOS6及以下系统,收到通知:%@", [selflogDic:userInfo]);
}
- (void)application:(UIApplication*)application
didReceiveRemoteNotification:(NSDictionary*)userInfo
fetchCompletionHandler:
(void(^)(UIBackgroundFetchResult))completionHandler {
[JPUSHServicehandleRemoteNotification:userInfo];
NSLog(@"iOS7及以上系统,收到通知:%@", [selflogDic:userInfo]);
//应用正处于前台状态下,不会收到推送消息,因此在此处需要额外处理一下
if(application.applicationState==UIApplicationStateActive) {
UIAlertController*alert = [selfalertControllerTitle:@"收到推送消息"message:userInfo[@"aps"][@"alert"]];
[self.window.rootViewControllerpresentViewController:alertanimated:YEScompletion:nil];
}
if(application.applicationState==UIApplicationStateInactive) {
[selfgoToMessageViewController];
}
completionHandler(UIBackgroundFetchResultNewData);
}
//本地通知的处理
- (void)application:(UIApplication*)application
didReceiveLocalNotification:(UILocalNotification*)notification {
[JPUSHServiceshowLocalNotificationAtFront:notificationidentifierKey:nil];
}
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#pragma mark- JPUSHRegisterDelegate
//App在前台获取通知———>但是不能展现
- (void)jpushNotificationCenter:(UNUserNotificationCenter*)centerwillPresentNotification:(UNNotification*)notification withCompletionHandler:(void(^)(NSInteger))completionHandler {
NSDictionary* userInfo = notification.request.content.userInfo;
UNNotificationRequest*request = notification.request;//收到推送的请求
UNNotificationContent*content = request.content;//收到推送的消息内容
NSNumber*badge = content.badge;//推送消息的角标
NSString*body = content.body;//推送消息体
UNNotificationSound*sound = content.sound;//推送消息的声音
NSString*subtitle = content.subtitle;//推送消息的副标题
NSString*title = content.title;//推送消息的标题
//UNPushNotificationTrigger(远程通知触发)
if([notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
[JPUSHServicehandleRemoteNotification:userInfo];
NSLog(@"iOS10前台收到远程通知:%@", [selflogDic:userInfo]);
}
//本地通知触发
else{
NSLog(@"iOS10前台收到本地通知:{\nbody:%@,\ntitle:%@,\nsubtitle:%@,\nbadge:%@,\nsound:%@,\nuserInfo:%@\n}",body,title,subtitle,badge,sound,userInfo);
}
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);//需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以设置
}
//点击通知进入App
- (void)jpushNotificationCenter:(UNUserNotificationCenter*)centerdidReceiveNotificationResponse:(UNNotificationResponse*)response withCompletionHandler:(void(^)())completionHandler {
NSDictionary* userInfo = response.notification.request.content.userInfo;
UNNotificationRequest*request = response.notification.request;//收到推送的请求
UNNotificationContent*content = request.content;//收到推送的消息内容
NSNumber*badge = content.badge;//推送消息的角标
NSString*body = content.body;//推送消息体
UNNotificationSound*sound = content.sound;//推送消息的声音
NSString*subtitle = content.subtitle;//推送消息的副标题
NSString*title = content.title;//推送消息的标题
//UNPushNotificationTrigger(远程通知触发)
if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
[JPUSHServicehandleRemoteNotification:userInfo];
NSLog(@"iOS10程序关闭后 通过点击推送进入程序弹出的通知:%@", [selflogDic:userInfo]);
[selfgoToMessageViewController];
}
//本地通知触发
else{
NSLog(@"iOS10收到本地通知:{\nbody:%@,\ntitle:%@,\nsubtitle:%@,\nbadge:%@,\nsound:%@,\nuserInfo:%@\n}",body,title,subtitle,badge,sound,userInfo);
}
completionHandler();//系统要求执行这个方法
}
#endif
// log NSSet with UTF8
// if not ,log will be \Uxxx
- (NSString*)logDic:(NSDictionary*)dic {
if(![diccount]) {
returnnil;
}
NSString*tempStr1 =
[[dicdescription]stringByReplacingOccurrencesOfString:@"\\u"
withString:@"\\U"];
NSString*tempStr2 =
[tempStr1stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];
NSString*tempStr3 =
[[@"\""stringByAppendingString:tempStr2]stringByAppendingString:@"\""];
NSData*tempData = [tempStr3dataUsingEncoding:NSUTF8StringEncoding];
NSString*str =
[NSPropertyListSerializationpropertyListFromData:tempData
mutabilityOption:NSPropertyListImmutable
format:NULL
errorDescription:NULL];
returnstr;
}
#pragma mark弹窗处理
-(UIAlertController*)alertControllerTitle:(NSString*)title
message:(NSString*)msg{
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:titlemessage:msgpreferredStyle:UIAlertControllerStyleAlert];//Alert警告
//通过UIAlertActionStyle,您可以选择如下三种动作样式:常规(default)、取消(cancel)以及警示(destruective)。
UIAlertAction*cancelAction = [UIAlertActionactionWithTitle:@"知道了"style:UIAlertActionStyleCancelhandler:nil];
__weaktypeof(self)weakSelf =self;
UIAlertAction*doAction = [UIAlertActionactionWithTitle:@"去看看"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {
//取出物流消息控制器
[weakSelfgoToMessageViewController];
}];
[alertControlleraddAction:cancelAction];
[alertControlleraddAction:doAction];
returnalertController;
}
7.iOS SDK FAQhttp://docs.jiguang.cn/jpush/client/iOS/ios_faq/