检测“允许通知” iOS8开启/关闭 [英] detect "Allow Notifications" is on/off for iOS8
问题描述
我正在尝试检测iOS 8中应用的本地通知设置
I am trying to detect the Local notification settings for the App in iOS 8
UIUserNotificationSettings
,它当我打开所有Badge,Sound&提醒。
for UIUserNotificationSettings
, it returns me 7 as I have turned on all Badge, Sound & Alert.
在设置中,我关闭了允许通知,应用程序仍然返回7用于UIUserNotificationSettings(徽章,声音和警报开启)。有没有办法检测允许通知
开/关?
In the setting, I switch off "Allow Notification" , the app still return me 7 for UIUserNotificationSettings (Badge, Sound & Alert on). Is there a way to detect "Allow Notification
" on/off?
- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
NSLog(@"---notificationSettings.types %d" , notificationSettings.types );
if(notificationSettings.types!=7){
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Please turn on Notification"
message:@"Go to Settings > Notifications > App.\n Switch on Sound, Badge & Alert"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert show];
}
}
推荐答案
方法自iOS8以来, enabledRemoteNotificationTypes
已被弃用。
Method enabledRemoteNotificationTypes
is deprecated since iOS8.
要检查iOS8中的远程通知状态,您可以调用
To check remote notifications status in iOS8 you can call
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
如果用户在设置中禁用通知,它将返回NO。 上的文档
isRegisteredForRemoteNotifications
it will return NO if user disable notifications in Settings. Documentation on isRegisteredForRemoteNotifications
或者您可以检索所有当前通知设置:
Or you can retrieve all current notification settings:
[[UIApplication sharedApplication] currentUserNotificationSettings];
文档 currentUserNotificationSettings
这篇关于检测“允许通知” iOS8开启/关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!