在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送
From: http://saeapns.sinaapp.com/doc.html
1,在iOS开发者中心: iOS Provisioning Portal 创建一个AppID,如图:
2,生成iOS Push Service证书,如图:
-
按照上述提示操作:
-
回到iOS Provisioning Portal:
-
点击“Download”下载iOS Push Service证书文件,如图:
3,导入证书文件到keychain:双击即可
4,生成ck.pem
-
导出cert.p12:
-
导出key.p12:
-
得到这样两个文件:
-
接下来打开终端:
-
输入命令:openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
-
然后输入命令:openssl pkcs12 -nocerts -out key.pem -in key.p12
-
最后合并成一个ck.pem文件:
-
输入命令:cat cert.pem key.pem > ck.pem
-
得到一个ck.pem文件:
5, 生成并安装Profile文件:
6, 上传ck.pem到SAE, 如图:
7, 客户端程序:
-
设置profile:
-
在info.plist中设置Bundle identifier:
-
在合适的位置加入下面代码,将你的应用注册到消息中心:
-
1234567891011121314
-
(IBAction
)action:(
id
)sender
{//注册到消息中心:
[[
UIApplication
sharedApplication]
registerForRemoteNotificationTypes
UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert
|UIRemoteNotificationTypeNewsstandContentAvailability)];
}
-
在AppDelegate中加入下面代码:
-
12345678910111213141516171819202122232425262728