集成过程遇到的问题:
一、信鸽推送平台上传的验证证书,和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)];
}
三、在信鸽平台上推送信息进行测试