1、客户端通过下面代码像APNS注册push,表明push的类型,iOS8之后对注册推送有了新的API
#if !TARGET_IPHONE_SIMULATOR
if (iOS8) {
UIUserNotificationType notifyType = UIUserNotificationTypeAlert|UIUserNotificationTypeSound|UIUserNotificationTypeBadge;
UIUserNotificationSettings *notifySet = [UIUserNotificationSettings settingsForTypes:notifyType categories:nil];
[[UIApplication sharedApplication]registerForRemoteNotifications];
[[UIApplication sharedApplication]registerUserNotificationSettings:notifySet];
}
else {
UIRemoteNotificationType notifyType = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert;
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:notifyType];
}
#endif
2、app注册后会调用 application delegate 中的代理方法
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{ //然后app会把这个deviceToken以及一些其他的信息发给后台或者第三方推送平台,当需要发送push的时候后台就会取出要发送的设备的deviceToken,组合特定格式的字符串,然后将其发送到APNS,APNS可以根据与之建立链接的后台所使用证书判断是那个app请求发送的推送,继而把推送发送到deviceToken的设备上
[[EaseMob sharedInstance]application:application didReceiveRemoteNotification:deviceToken];
[_modelMessage getuiReceiveRemoteNotification:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[MessageModel application:application didFailToRegisterForRemoteNotificationsWithError:error];
[[EaseMob sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error];
}
3、对于APNS来说,device Token是设备的标示符,与设备的唯一标示符不同,处于安全与隐私的原因,当设备被擦除的时候,Token值必须变化。
4、同一台设备在development 和 distribution情况下,收到的device Token 是不同的,而token是与app无关的。
5、device Token的生成:每台正常的iPhone有一个唯一的设备证书和秘钥,通过这两者获得的,如果经过某种手段使得设备上证书是一样的,那么就有很大的概率使不同设备具有相同的device Token值,就会出现彼此间puch串发的现象6、iOS5之后uniqueIdentifier会逐步被废除,取而代之使用设备的Mac地址MD5计算后的结果作为作为设备的唯一标识,这个对推送不影响