iOS PUSH实现的简单步骤

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消息了。服务器那边的设置我就不再累述了···

我写得简单了点。这里有更详细的描述。···

http://tiny4cocoa.com/thread-1406-1-1.html

PS:但是导出证书的地方步骤还没有官方来得简洁:https://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ProvisioningDevelopment/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW1

{

  1. Open Keychain Access utility and click the My Certificates category in the left pane.

  2. Find the certificate you want to install and disclose its contents.

    You'll see both a certificate and a private key.

  3. Select both the certificate and key, choose File > Export Items, and export them as a Personal Information Exchange (.p12) file.

  4. Servers implemented in languages such as Ruby and Perl often are better able to deal with certificates in the Personal Information Exchange format. To convert the certificate to this format, complete the following steps:

    1. In KeyChain Access, select the certificate and choose File > Export Items. Select the Personal Information Exchange (.p12) option, select a save location, and click Save.

    2. Launch the Terminal application and enter the following command after the prompt:

      openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes

  5. Copy the .pem certificate to the new computer and install it in the appropriate place

}

你可能感兴趣的:(ios,apple,xcode,服务器,application,Exchange)