我的应用程序中有通知功能,它适用于所有人。但只有少数成员设备令牌本身才会出现null。任何人都可以帮我解决这个问题吗?他们使用的是iOS 9.2版本,设备是iPhone 6和5s。
提前谢谢大家。
答案 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)];
}
<强> 两个 强>
用户点击“不允许推送
”如果某些用户发生这种情况,那么这些用户的iPhone就越狱了。 确保谁将设备令牌设为null并不是越狱
检查是否已越狱
NSString *path = @"/Applications/Cydia.app";
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
if (fileExists) {
//device is jailbroken
} else {
//device is not jailbroken
}
<强> OR 强>
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
if ([info objectForKey: @"SignerIdentity"] != nil)
{
/* do something */
}
答案 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