远程通知
1、后台推送通知到 苹果服务器(APNS)
2、苹果服务器(APNS)把通知发送到苹果手机端
3、手机接收通知
一、后台推送通知到 苹果服务器(APNS)
下载一个APNS的证书,用PHP写的后台 是.pem问价 如果是 java /.net.p12
1、下载APNS证书:一个应用必须要有一个与他对应的证书bundleID
(1)申请APNS证书的时候 需要填写一个appID 与app的bundleID 对应**
这个证书可以通过我们前面生成的两个文件中得到。
1、将aps_developer_identity.cer转换成aps_developer_identity.pem格式
- openssl x509 -in aps_developer_identity.cer -inform DER -out aps_developer_identity.pem -outform PEM
2、将p12格式的私钥转换成pem
1. openssl pkcs12 -nocerts -out Push_Noenc.pem -in Push.p12
3、创建p12文件
- openssl pkcs12 -export -in aps_developer_identity.pem -inkey Push_Noenc.pem -certfile Push.certSigningRequest -name “aps_developer_identity” -out aps_developer_identity.p12
这样我们就得到了在.net或java等后台应用程序中使用的证书文件:aps_developer_identity.p12
二、苹果服务器(APNS)把通知发送到苹果手机端
需要提供给后台服务器一个deviceToken号 以及通知的内容一同发送给苹果服务器
iOS添加代码如下:
三、手机接收通知
1、注册通知
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc]init];
categorys.identifier=@"Bruce.com.Where";
UIUserNotificationSettings *userNotifiSetting = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:[NSSet setWithObjects:categorys,nil]];
[[UIApplication sharedApplication] registerUserNotificationSettings:userNotifiSetting];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}else {
//注册远程推送
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
添加到didFinishLaunchingWithOptions
2、应用程序内部 提示通知
当接受到远程通知 就会自动调用
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
userInfo 包含了 具体通知的内容
}
全部搞定之后 还需设置XCode