苹果推送

1.    在官网控制台上传推送证书

1)登录控制台,点击进入im管理页面,选择对应应用,点击IM基础功能配置
2)点击推送证书,添加对应环境的.p12证书
 
 
 
 

2.    代码实现注册apns和上传devicetoken

示例代码如下:
 
  • //iOS8 注册APNS
  •  if ([application respondsToSelector:@selector(registerForRemoteNotifications)]) {
  •  
  •  UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
  •  UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
  •  [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  •  
  •  } else {
  •  UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeBadge |
  •  UIRemoteNotificationTypeSound |
  •  UIRemoteNotificationTypeAlert;
  •  [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes];
  •  }
  •  
  • //上传devicetoken
  • - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  •  #warning 将获取到的token传给SDK,用于苹果推送消息使用
  •  [[ECDevice sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  • }
 

3.    小结及注意事项

1)推送证书上传即生效;
2)生产环境调试推送功能需要用发布证书打包测试;
3)对于iOS 10而言,需将Capabilities -> Push Notifications 开启,如图所示:
4)要实现远程推送需要勾选Background Modes里的Remote notifications,如图所示:
5)
apns推送通知参数说明:
r:receiver(接收者);
s:sender(发送者);
c:扩展内容,转换成json串以后可以从中获取到callid(通话唯一标识);
sound:推送铃声;
alert:推送通知内容;
badge:角标数。
示例如下:
im消息:
{"s":"15300111601","aps":{"sound":"default","alert":"111601:健康快乐","badge":3},"r":"g801343229"}
离线呼叫:
{"s":"89160","r":"20797","c":"{\"callid\":\"202020202020202020202020202020202020\"}","aps":{"sound":"default","alert”:”12:发来一个视频呼叫"}