读书人

ios的push兑现

发布时间: 2012-10-05 15:34:34 作者: rapoo

ios的push实现

证书什么的下面两个参考链接写的非常不错:

http://luoyl.info/blog/2012/02/apple_push_notification_guide/

http://blog.sina.com.cn/s/blog_4c925dca01010tmp.html


需要注意的是,警告通知其实是自己弹出来的,具体的流程如下:

ios的push兑现


而且push消息有自己比较独特的json格式,apple的api说的很清楚:http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW10

{
    "aps" : { "alert" : "Message received from Bob" },
    "acme2" : [ "bang",  "whiz" ]
}

github里面找到一个开源的apple push server:https://github.com/stefanhafeneger/PushMeBaby

使用很简单

1.将自己的cer文件(obj c上不用p12文件)导入工程

2.修改初始化语句

- (id)init {

self = [superinit];

if(self !=nil) {

self.deviceToken =@"94b77ce5 bca83eb2 af0b0827 a7bbs633 3efc6ffdd e4fdw20a dd8cd2d7 5222c2e2";

//设置device token,

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken获取到的

self.payload =@"{\"aps\":{\"alert\":\"This is some fancy message.\",\"badge\":1}}";

///设置alert信息

self.certificate = [[NSBundlemainBundle] pathForResource:@"aps_development"ofType:@"cer"];

//设置证书路径

}

return self;

}

3.运行


good luck






读书人网 >操作系统

热点推荐