这是我用于RemoteNotificationType的代码:
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
我得到的错误是:
2014-09-29 15:46:47.416 Dummy [258:21766]在iOS 8.0及更高版本中不支持enabledRemoteNotificationTypes。
如果有人能给我解决方案,那将是一个很好的帮助。
答案 0 :(得分:18)
您也可以使用此代码:
if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {
UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
if (types == UIUserNotificationTypeNone) {
// Do something
}
} else {
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone) {
// Do something
}
}
如果您只想检查用户是否已注册远程通知,请使用此选项:
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
BOOL isRegisteredForRemoteNotifications = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
if (isRegisteredForRemoteNotifications) {
// Do something
}
} else {
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone) {
// Do something
}
}
答案 1 :(得分:16)
使用此条件在iOS 7和之前的iOS 8中提供支持
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
NSUInteger rntypes;
if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) {
rntypes = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
}else{
rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
}
答案 2 :(得分:2)
请使用以下方法 -
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]
或
[[UIApplication sharedApplication] currentUserNotificationSettings]
在iOS 8中检索启用了用户的远程通知和用户通知设置。