首先,要先到苹果开发者中心创建推送证书,这个可以参考下IM的文档:申请远程推送证书。
然后,将证书的p12文件上传到管理后台,如图,登录客服系统,来到管理员模式--渠道管理--手机APP 页面:
1、如果手机APP里的【直接登录IM关联后台】按钮可点击,那这个app关联就是快速创建的,点击即可进入管理后台上传证书
2、如果手机APP里的【直接登录IM关联后台】按钮不可点击,那这个app关联就是手动关联的,要到IM的Console后台上传证书:Console后台
其次,是代码方面
1、初始化sdk时传证书名称,参考文档:初始化
//推送证书名字
option.apnsCertName = @"your apnsCerName";//(集成离线推送必填)
2、注册远程通知
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
//注册推送, 用于iOS8以及iOS8之后的系统
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
} else {
//注册推送,用于iOS8之前的系统
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
}
3、绑定devicetoken
您注册了推送功能,iOS 会自动回调以下方法,得到 deviceToken,您需要将 deviceToken 传给 SDK。
// 将得到的deviceToken传给SDK
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[HDClient sharedClient] bindDeviceToken:deviceToken];
});
}
// 注册deviceToken失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"error -- %@",error);
}
4、将程序进入后台、返回前台的状态传给环信
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[HDClient sharedClient] applicationDidEnterBackground:application];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[HDClient sharedClient] applicationWillEnterForeground:application];
}
最后,附上离线推送收不到的排查步骤,大多数都是这里面的原因:离线推送收不到怎么办(客服)
网友评论