我们项目需要获取用户设备的deviceToken,发现证书配置都正确,并且开启时候也是有给予设置允许通知的权限。但是个别终端还是无法获取到token,有的却可以。请教下这个是什么原因会导致个别可以个别不行?(网络环境都相同)
阿神2017-04-17 18:03:06
I happened to encounter the same problem as the original poster today. I can get the token on 5s, but not on 6s.
原因如下:
我在 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中判断是否登录的时候提前使用了 return YES 导致整个方法没有执行完,我把return去掉就解决问题了。
代码如下:
//注册代码
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
//导致有些设备获取不了token,有些设备能够获取token的代码
if(![kUSER_DEFAULT boolForKey:kIS_LOGIN])
{
LoginViewController *loginVC = [[LoginViewController alloc] init];
self.window.rootViewController = loginVC;
return YES; (把此return YES 删除)
}
return YES
//获取token代码
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
HSLog(@"DeviceToken:%@", deviceToken]);
}
黄舟2017-04-17 18:03:06
didFailToRegisterForRemoteNotificationsWithError Is there any hint in this callback? Also, which version of iOS is your device on? Is it easy to post the code for registering APN?