标签:
远程推送的原理图
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
第四步,向服务器发送token(开启信鸽推送)
[XGPush startApp:2200150400 appKey:@"IX2ZP236S3FZ"];
第一步1.注册
//判断系统的版本是否大于8.0
//系统刚刚启动脚标清零
application.applicationIconBadgeNumber = 0;
if ([[[UIDevice currentDevice]systemVersion ]floatValue]>=8.0) {
//如果大于调用的8.0方法
//设置远程通知配置
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]];
[application registerForRemoteNotifications];
}
else{
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
}
return YES;
}
//注册成功
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
//第五步,服务器发送token,信鸽推送,注册设备
[XGPush registerDevice:deviceToken];
NSLog(@"成功%@",deviceToken);
//在这里取向服务器发送deviceToken
//post请求deviceToken是body体
}
//注册失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"chengg");
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//userInfo字典中存储关于推送的信息,可以有ID去拼接
application.applicationIconBadgeNumber = 0;
}
二.上传证书
2.1 登陆开发者账号,下载测试和生产证书
2.2 还有在第三方服务器上传"开发证书"和"生产证书".需要的是.pem类型的证书,需要打开终端,(cd 文件夹路径去掉文件名后面的都去掉 ,回车,openssl pkcs12 -in 测试(或生产)证书.p12 -out 测试(或生产)证书.pem -nodes 粘贴上,回车,会在原来证书的文件夹里多出两个.pem类型的证书,此时可以上传到服务器上了,哈哈!)
标签:
原文地址:http://www.cnblogs.com/lsh1234/p/4850231.html