苹果iOS APNS消息推送通知

参考链接:

http://www.tairan.com/archives/194

http://www.tairan.com/archives/240

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW2

操作过程:

1、在开发者中心配置AppID,enable推送通知选项

undefined

2、在APP ID的推送通知选项中分别创建dev和dis证书,此两种证书用于device、provider、apns间注册通讯验证身份用,跟app本身编译发布使用的证书不同,生成证书时需要选择.certSigningRequest证书请求文件,此为私钥,生成证书后要下载并安装到开发mac机器上,下载到本地双击即可安装

undefined

undefined

下面截图中,.certSigningRequest为keristef@163.com这个apple ID的证书申请文件(对应私钥为keristef),证书为Chenjin这个Apple ID下面生成,证明certSigningRequest随便生成均可,验证了泰然教程中所说 undefined

3、导出APNS证书文件并整理为pem格式,在keyaccess实用工具中,同时选中证书和私钥,右键导出为p12格式文件(需要指定私钥保护密码,在provider发送消息时会使用此保护密码),再使用openssl命令转为pem格式 undefined

apple-MacB:SimplePush apple$ openssl pkcs12 -in SaleMaster_APNS_dis.p12 -out SaleMaster_APNS_dis.pem -nodes

Enter Import Password:

MAC verified OK

undefined

4、创建ProvisionProfile,分别为dev和dis版本 以dev版本为例,注意选择正确的AppID,证书选择dev开发者证书,设备注意选择自己的开发设备

undefined

5、Xcode中选择正确的codesign和profile

undefined

6、添加推送消息处理代码,参考网上各种教程

7、调测模拟,使用SimplePush.php作为模拟推送消息服务器,具体见如下 下载这些SimplePush代码并解压缩,你需要在simplepush.php做些改变。

//把你的设备标识写在这里(没有空格): $deviceToken = '0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78';

//密码放在这里 $passphrase = 'pushchat';

// 把你的推送消息放在这里: $message = 'My first push notification!'; 你需要从app中拷贝device token到$deviceToken变量。确定删掉了空格以及分隔符。它应该是64位的十六进制字符。把你私钥密码短语放到$passphrase变量,以及你想发送的信息放到$message中。

拷贝你的ck.pem 文件到SimplePush目录,记住,这个ck.pem文件同时包含你的证书和私钥。

然后打开一个终端并键入:

$ php simplepush.php

上述命令执行完不久即可在手机上收到消息如下图:

2014-05-28 215821

原文地址:https://www.cnblogs.com/wolfcamel/p/4302435.html