差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 上一修订版 两侧同时换到之后的修订记录 | ||
im:ios:apns:deploy [2020/03/17 07:23] huanxinfudh [客户端如何申请DeviceToken] |
im:ios:apns:deploy [2022/01/20 12:17] dujiepeng [SDK的运行状态] |
||
---|---|---|---|
行 4: | 行 4: | ||
* 当 App 在前台可见的时候,SDK 处于前台活跃状态,此时是使用 SDK 长连接接收消息。 | * 当 App 在前台可见的时候,SDK 处于前台活跃状态,此时是使用 SDK 长连接接收消息。 | ||
| | ||
- | * 当 App 进入后台且在2分钟之内的时候,SDK 处于后台活跃状态,此时是使用 SDK 长连接接收消息(用户根据需要实现本地通知,否则将不会有本地通知提示弹出)。 | + | * 当 App 进入后台,短时间内 SDK 处于后台活跃状态,此时是使用 SDK 长连接接收消息(用户根据需要实现本地通知,否则将不会有本地通知提示弹出)。 |
| | ||
- | * 当 App 进入后台超过2分,被系统挂起,此时 SDK 处于不活跃状态,或者是主动把App进程杀死,此时如果有新消息,是通过苹果的 APNs 服务进行提醒的。当 App 再次启动,SDK 会去服务器拉取不活跃期间的消息。 | + | * 当 App 进入后台被系统挂起,此时 SDK 处于不活跃状态,或者是主动把App进程杀死,此时如果有新消息,是通过苹果的 APNs 服务进行提醒的。当 App 再次启动,SDK 会去服务器拉取不活跃期间的消息。 |
**注意:**''由于本地通知和 APNs 不好区分,调试时建议您将 App 进程杀死,确保所有的提醒都是来自于 APNs 推送。'' | **注意:**''由于本地通知和 APNs 不好区分,调试时建议您将 App 进程杀死,确保所有的提醒都是来自于 APNs 推送。'' | ||
行 96: | 行 96: | ||
此处需要记住密码,后面需要用到。 | 此处需要记住密码,后面需要用到。 | ||
+ | ''注意:导出p12证书时,设置证书的密码长度不要超过20个字符,建议使用纯英文或者数字组合,不建议带特殊字符'' | ||
{{:im:300iosclientintegration:apns_create19.jpg?800|}} | {{:im:300iosclientintegration:apns_create19.jpg?800|}} | ||
行 126: | 行 127: | ||
为证书起名,并记住名称,后续有用。选择上传证书,将上一步中生成的P12文件上传,并设置导出时设置的密码。选择证书类型,此处是【开发环境】(如果之前用的是production,则此处应该选择生产)。填写应用包名,应为**bundle id**,点击上传,完成上传证书操作。 | 为证书起名,并记住名称,后续有用。选择上传证书,将上一步中生成的P12文件上传,并设置导出时设置的密码。选择证书类型,此处是【开发环境】(如果之前用的是production,则此处应该选择生产)。填写应用包名,应为**bundle id**,点击上传,完成上传证书操作。 | ||
+ | |||
+ | ''注意:证书的名称和密码的长度不要超过20个字符,建议使用纯英文或者数字组合,不建议带特殊字符'' | ||
{{:im:ios:apns:ios证书.png?nolink|}} | {{:im:ios:apns:ios证书.png?nolink|}} | ||
行 174: | 行 177: | ||
</code> | </code> | ||
+ | |||
+ | ===== 使用在线推送通道 ===== | ||
+ | |||
+ | 与APNs离线推送使用苹果厂商推送通道不同,在线推送通道使用环信长连接接收推送,之后以本地通知的形式展示推送消息,可以有效提升推送到达率。 | ||
+ | 集成在线推送过程如下: | ||
+ | - 申请本地通知权限 | ||
+ | - 启用SDK在线推送 | ||
+ | - 处理Delegate | ||
+ | |||
+ | ==== 申请本地通知权限 ==== | ||
+ | 由于要使用本地通知展示推送消息,你需要在App中需要申请权限,过程如下: | ||
+ | <code> | ||
+ | UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | ||
+ | [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) { | ||
+ | | ||
+ | }]; | ||
+ | </code> | ||
+ | |||
+ | ==== 启用SDK在线推送 ==== | ||
+ | 在启用APNs在线推送前,你需要完成IM SDK的初始化工作 | ||
+ | |||
+ | SDK初始化完成后,启用APNs在线推送过程如下: | ||
+ | <code> | ||
+ | [[EMLocalNotificationManager sharedManager] launchWithDelegate:self]; | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | ==== 处理Delegate ==== | ||
+ | 在启用在线通道过程中,SDK会重写**[UNUserNotificationCenter currentNotificationCenter]**的delegate,如果要处理其他本地通知,需要实现**EMLocalNotificationDelegate**,过程如下 | ||
+ | <code> | ||
+ | #pragma mark - EMLocalNotificationDelegate | ||
+ | - (void)emuserNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | ||
+ | { | ||
+ | // // 这里处理其他本地通知 | ||
+ | completionHandler(UNNotificationPresentationOptionAlert); | ||
+ | } | ||
+ | - (void)emuserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler | ||
+ | { | ||
+ | NSDictionary* userInfo = response.notification.request.content.userInfo; | ||
+ | // 这里处理其他本地通知 | ||
+ | completionHandler(); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== 进阶 ==== | ||
+ | iOS的本地通知管理模块**UNUserNotificationCenter**是单例,一个App | ||
+ | 中只能有一个实例,如果在启用SDK在线推送之后,App又重写了**[UNUserNotificationCenter currentNotificationCenter].delegate**,会把SDK中的delegate覆盖掉,此时需要在App实现的**UNUserNotificationCenterDelegate**中,调用SDK的相关处理,过程如下 | ||
+ | <code> | ||
+ | #pragma mark - UNUserNotificationCenterDelegate | ||
+ | |||
+ | - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | ||
+ | { | ||
+ | // 处理其他通知 | ||
+ | ... | ||
+ | // 调用SDK推送在线通道处理 | ||
+ | [[EMLocalNotificationManager sharedManager] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; | ||
+ | } | ||
+ | |||
+ | - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler | ||
+ | { | ||
+ | | ||
+ | // 处理其他通知 | ||
+ | ... | ||
+ | // 调用SDK推送在线通道处理 | ||
+ | [[EMLocalNotificationManager sharedManager] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; | ||
+ | } | ||
+ | </code> | ||
===== 常见问题 ===== | ===== 常见问题 ===== | ||
==== 如何实现本地通知 ==== | ==== 如何实现本地通知 ==== |