”Apple Development Push Services”,导出p12文件,保存为 apns-dev-cert.p12 文件。
展开“Apple Development Push Services” 对“Private Key”做同样操作,保存为 apns-dev-key.p12 文件。
需要通过终端命令将这些文件转换为PEM格式:
openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
如果你想要移除密码,要么在导出/转换时不要设定或者执行:
openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
最后,你需要将键和许可文件合成为apns-dev.pem文件,此文件在连接到APNS时需要使用:
cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem
如果出错 :确认证书路径正确。
- (void)application:(UIApplication*)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"设备令牌: %@", deviceToken);
NSString *tokeStr = [NSString stringWithFormat:@"%@",deviceToken];
}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeSound| UIRemoteNotificationTypeAlert)];
}