我正在尝试检测 iOS 8 中应用程序的本地通知设置
for UIUserNotificationSettings
,它返回 7,因为我已打开所有徽章、声音和警报。
在设置中,我关闭“允许通知”,应用程序仍然返回给我 UIUserNotificationSettings 7(徽章、声音和警报打开)。有没有办法检测“允许Notification
“ 开关?
- (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];
}
}
Method enabledRemoteNotificationTypes
自 iOS8 起已弃用。
要检查 iOS8 中的远程通知状态,您可以调用
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
如果用户在设置中禁用通知,它将返回 NO。文档 https://developer.apple.com/library/prerelease/iOS/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/isRegisteredForRemoteNotifications on isRegisteredForRemoteNotifications
或者您可以检索所有当前的通知设置:
[[UIApplication sharedApplication] currentUserNotificationSettings];
文档 https://developer.apple.com/library/prerelease/iOS/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/currentUserNotificationSettings on currentUserNotificationSettings
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)