我在互联网上查找了如何使用 IOS 8 创建本地通知。我找到了很多文章,但没有一篇文章解释了如何确定用户是否打开或关闭了“警报”。有人可以帮帮我吗!!!我更喜欢使用 Objective C 而不是 Swift。
您可以使用以下方法检查它UIApplication
's 当前用户通知设置 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_class/index.html#//apple_ref/occ/instm/UIApplication/currentUserNotificationSettings
if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]){ // Check it's iOS 8 and above
UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (grantedSettings.types == UIUserNotificationTypeNone) {
NSLog(@"No permiossion granted");
}
else if (grantedSettings.types & UIUserNotificationTypeSound & UIUserNotificationTypeAlert ){
NSLog(@"Sound and alert permissions ");
}
else if (grantedSettings.types & UIUserNotificationTypeAlert){
NSLog(@"Alert Permission Granted");
}
}
希望这有帮助,如果您需要更多信息,请告诉我
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)