文章标题
2015-10-10 17:42
239 查看
远程通知
1、后台推送通知到 苹果服务器(APNS)2、苹果服务器(APNS)把通知发送到苹果手机端
3、手机接收通知
一、后台推送通知到 苹果服务器(APNS)
下载一个APNS的证书,用PHP写的后台 是.pem问价 如果是 java /.net.p12
1、下载APNS证书:一个应用必须要有一个与他对应的证书bundleID
(1)申请APNS证书的时候 需要填写一个appID 与app的bundleID 对应**
https://developer.apple.com/
这个证书可以通过我们前面生成的两个文件中得到。
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
相关文章推荐
- ss查看状态
- MJRefreshFooterView
- java基础学习GUI编程
- 中缀表达式转化为后缀表达式
- AndroidSwipeLayout:最强大的 Swipe Layout
- 一个二维阵列蛇的实现
- 对自己的忠告
- UIActionSheet
- 采集数据 去除最大值最小值 代码
- helloword
- Computer English - (2) Database & Info Systems
- Android - 文件读写操作 总结
- 使用国内镜像源来加速python pypi包的安装
- 栅格重采样
- Tomcat 7.0 servlet @WebServlet
- UIAlertView带textField
- 存储过程[st_MES_RptInspectShipment]
- Gerrit代码管理服务器配置
- C语言:typedef struct与指针
- mongodb 集群安 装