本文介绍了检查是否在 IOS 8 中启用了本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在互联网上查看了如何使用 IOS 8 创建本地通知.我找到了很多文章,但没有解释如何确定用户是否已打开或关闭警报".有人可以帮我吗!!!我更喜欢使用 Objective C 而不是 Swift.
I've looked all over the internet for how to create local notifications with IOS 8. I found many articles, but none explained how to determine if the user has set "alerts" on or off. Could someone please help me!!! I would prefer to use Objective C over Swift.
推荐答案
您可以使用 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");
}
}
希望这有帮助,如果您需要更多信息,请告诉我
Hope this helps , Let me know if you need more info
这篇关于检查是否在 IOS 8 中启用了本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!