信鸽推送集成
2016-04-08 20:13
363 查看
集成过程遇到的问题:
一、信鸽推送平台上传的验证证书,和xcode使用的证书不匹配,导致token值收不到, 即信鸽使用一个账号申请推送
二、一定写如下函数,定位收不到token的原因
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
集成步骤:
一、在AppDelegate文件的didFinishLaunchingWithOptions函数函数中增加
二、在Appdelegate文件中增加如下函数
三、在信鸽平台上推送信息进行测试
一、信鸽推送平台上传的验证证书,和xcode使用的证书不匹配,导致token值收不到, 即信鸽使用一个账号申请推送
二、一定写如下函数,定位收不到token的原因
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
集成步骤:
一、在AppDelegate文件的didFinishLaunchingWithOptions函数函数中增加
[super application:application didFinishLaunchingWithOptions:launchOptions]; //信鸽推送 [XGPush startApp:(int)[AppHelper appIdForXG] appKey:[AppHelper appKeyForXG]]; //注销之后需要再次注册前的准备 void (^successCallback)(void) = ^(void){ //如果变成需要注册状态 if(![XGPush isUnRegisterStatus]) { [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"deviceToken"]; //iOS8注册push方法 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue]; if(sysVer < 8){ [self registerPush]; } else{ [self registerPushForIOS8]; } #else //iOS8之前注册push方法 //注册Push服务,注册后才能收到推送 [self registerPush]; #endif } }; [XGPush initForReregister:successCallback]; //[XGPush registerPush]; //注册Push服务,注册后才能收到推送 //推送反馈(app不在前台运行时,点击推送激活时) //[XGPush handleLaunching:launchOptions]; //推送反馈回调版本示例 void (^successBlock)(void) = ^(void){ //成功之后的处理 NSLog(@"[XGPush]handleLaunching's successBlock"); }; void (^errorBlock)(void) = ^(void){ //失败之后的处理 NSLog(@"[XGPush]handleLaunching's errorBlock"); }; //清除所有通知(包含本地通知) //[[UIApplication sharedApplication] cancelAllLocalNotifications]; [XGPush handleLaunching:launchOptions successCallback:successBlock errorCallback:errorBlock];
二、在Appdelegate文件中增加如下函数
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{ NSLog(@"%@",[NSString stringWithFormat: @"Error: %@",error]); } - (void)registerPushForIOS8{ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ //Types UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; //Actions UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init]; acceptAction.identifier = @"ACCEPT_IDENTIFIER"; acceptAction.title = @"Accept"; acceptAction.activationMode = UIUserNotificationActivationModeForeground; acceptAction.destructive = NO; acceptAction.authenticationRequired = NO; //Categories UIMutableUserNotificationCategory *inviteCategory = [[UIMutableUserNotificationCategory alloc] init]; inviteCategory.identifier = @"ACTIONABLE"; [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault]; [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextMinimal]; NSSet *categories = [NSSet setWithObjects:inviteCategory, nil]; UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories]; [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; #endif } - (void)registerPush{ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; }
三、在信鸽平台上推送信息进行测试
相关文章推荐
- ionic
- android中的帧布局(frameLayout)
- F# 树
- 链表迭代器
- iOS简单动画效果
- 文章标题
- 密码验证合格程序(华为oj)
- 3、MongoDB数据库集合常用操作
- freemarker生成java代码
- 小米笔试题 风口的猪-中国牛市
- 关于ListView中点击item后背景色不改变,但是事件的确执行了
- hbase family qualifier设置
- HashMap实现原理,利用数组和链表存储元素
- HDU 4283 You Are the One(区间DP)
- 深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
- 00001--awk取时间段日志
- 扣丁学堂笔记第27天NDK、屏幕适配与APP上线
- iOS滑动条UISlider的使用方法
- busybox中tftp服务器使用命令
- 结对编程之黄金点游戏