我的情况如下:
重新安装我的应用并以编程方式获取推送通知设置,如下所示:
if ([[UIApplication sharedApplication]respondsToSelector:@selector(currentUserNotificationSettings)]){
UIUserNotificationSettings *noticationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!noticationSettings || (noticationSettings.types == UIUserNotificationTypeNone)) {
return NO;
}
return YES;
}
但是,notificationSettings.types
始终返回UIUserNotificationTypeNone
,但在设备的应用设置中,通知设置正在启用。
在这种情况下,有人可以帮助我获得正确的通知设置值吗?
答案 0 :(得分:2)
你应该检查
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]
致电前
[[UIApplication sharedApplication] currentUserNotificationSettings];
这是正确的代码:
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications] == NO)
return NO;
if ([[UIApplication sharedApplication]respondsToSelector:@selector(currentUserNotificationSettings)]){
UIUserNotificationSettings *noticationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!noticationSettings || (noticationSettings.types == UIUserNotificationTypeNone)) {
return NO;
}
return YES;
}
答案 1 :(得分:1)
[[UIApplication sharedApplication] currentUserNotificationSettings]
在打电话之前
[[UIApplication sharedApplication] registerUserNotificationSettings:]
返回错误的值。