建议尽快升级。使用 iOS 10 SDK 须要 Xcode 8 的支持。iOS 10 推出两周内,安装率就已经达到 48.16%,不升级 Xcode 8 并适配 iOS 10 意味着你如今可能已经损失了 50% 的高端客户,并且在将来的几个月内或许会陆续损失 90% 以上的客户。ios
projectName.entitlements
文件,请不要随意删除、修改:JPUSHService.h
、jpush-ios-2.1.9.a
。UserNotifications.framework
原先向系统注册并请求推送权限的代码是酱紫的,根据 iOS 8 之后及之前分两步:xcode
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];
}复制代码
如今在前面加了一段 iOS 10 的注册方法:ide
//Required
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];
}复制代码
在 Change 4 中的该行代码处会报警告:ui
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];复制代码
其中的 self 类必须实现
实现
- (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三种类型能够选择设置
}
- (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(); // 系统要求执行这个方法
}复制代码
其中:代理
willPresentNotification
在展现推送以前触发,能够在此替换推送内容,更改展现效果:内容、声音、角标。didReceiveNotificationResponse
在收到推送后触发,你原先写在 didReceiveRemoteNotification
方法里接收推送并处理相关逻辑的代码,如今须要在这个方法里也写一份:
这两个 iOS 10 的新特性,暂未包含在 JPush SDK 中,须要用户手动建立相应的 Target 并实现。code
主要负责修改推送内容、增长图片、gif、audio、video 展现。
收到推送小图 - 下拉 - 展现大图
cdn
用于彻底自定义推送展现 UI,响应用户操做事件,并即时更新推送展现 UI。
注意下图中点击 Accept 后,推送 UI 里日程表 UI 发生了刷新。
blog