设备令牌即将(null)仅适用于iPhone中的少数用户

时间:2016-01-28 06:03:23

标签: ios objective-c iphone apple-push-notifications

我的应用程序中有通知功能,它适用于所有人。但只有少数成员设备令牌本身才会出现null。任何人都可以帮我解决这个问题吗?他们使用的是iOS 9.2版本,设备是iPhone 6和5s。

提前谢谢大家。

3 个答案:

答案 0 :(得分:2)

didFinishLaunchingWithOptions的{​​{1}}中添加以下代码:

AppDelegate.m

这可能适用于iOS版本大于8.0。

答案 1 :(得分:2)

两种可能性

<强>

您错过了iOS 8及以上代码

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    NSLog(@"ios8 app");
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    NSLog(@"lower ios8 app");
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}

或者

<强> 两个

用户点击“不允许推送

编辑1

如果某些用户发生这种情况,那么这些用户的iPhone就越狱了。 确保谁将设备令牌设为null并不是越狱

编辑2

检查是否已越狱

NSString *path = @"/Applications/Cydia.app";
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];

if (fileExists) {
    //device is jailbroken
} else {
    //device is not jailbroken
}

Reference

<强> OR

NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
if ([info objectForKey: @"SignerIdentity"] != nil)
{
/* do something */
}

Reference

答案 2 :(得分:1)

转到设置 - &gt;你的应用 - &gt;通知 - &gt;切换允许通知 或尝试

if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert| UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge)];
}

在AppDelegate.m中的didFinishLaunchingWithOptions