3、新建一个项目
1). 创建一个"single view application" project,为省事,你设置的"Company Identifier" + "Production“必须和step 5创建的App ID的"bundle identifier"一致。
2). 在AppDelegate.m file的"didFinishLaunchingWithOptions" method里,添加下列代码 (用于为app register push notification feature):
// Let the device know we want to receive push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
3). 在AppDelegate.m file里添加下列2个methods (用来handle register remote notification with device token和register error的events)
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
4). 运行该app in real device (simulator doesn't support push notification)。这时你会在device上看到一个popup window (该窗口只会出现一次,重装app不会再出现),提示你该app会send push notification给你,如果同意则clickOK,不同意则click "Now allow”。如果选择了OK,那么在"Setting > Notifications“里会有你的app在list里。而且这时你的Xcode output console会显示你的device token。
5). export "PushDemo" private key to a ".p12" file(该文件会在后面生成apns provider的.p12 or .pem file时用到)
1). right click "PushDemo“ private key and select "Export ..."PushDemo
2). Save the private key as “PushDemoKey.p12” file, click Save button
3). 这时会让你输入2次用于加密该.p12 file的密码,例如用"123321",接着会要求你输入一次your mac account password
6).在5中生成的“PushDemoKey.p12” file和step 6生成的"aps_development.cer" file是用于APNS provider side的源文件,APNS Provider side进行push message时要用到的"cert + key" file就是通过这2个file来生成。该Step就是用来生成for APNS provider side (php version)要用到这个"cert + key" pem file.
1) open Terminal, go to Desktop (假设这2个file都在desktop里)










