A>本地钥匙串生成证书请求文件,XXX.certSignningRequest
B>developer.apple.com,创建新的appId,用于新的项目.这里有一点需要注意,identify要和工程中plist中的属性保持一致
C>在完成B之后Configurable一下push相关的项目,可以根据实际需求,分别选择developement或者production.在configrable的时候会用到步骤A中生成的certSignningRequest,最后我们可以得到XXX.csr证书文件。下载双击进行安装
D>再回到developer.apple.com,在provision中create新的XX.mobileprovision,OK之后down下来,然后在xcode中的organizer中添加
E>xcode创建新的工程,配置相关信息,着重强调identify.
F>在工程中的AppDelegate重写以下方法
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
NSLog(@"Registering for push notifications...");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
application.applicationIconBadgeNumber = 0; //程序开启,设置UIRemoteNotificationTypeBadge标识为0
}
//得到deviceToken
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(str);
}
//注册失败后输出相关信息
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(str);
}
//应用接收到push信息后我们自己的处理
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
}
当然了,最后还是要把一些本地的证书导出后给我们的服务器,这样服务器才能向APPLE发送消息,APPLE确定这些消息来源安全可靠的情况下,就会安装了对应APP的设备push消息了。服务器那边的设置我就不再累述了···
评论