检查IOS 8中是否启用了本地通知 [英] Check if Local Notifications are enabled in IOS 8

查看:166
本文介绍了检查IOS 8中是否启用了本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在互联网上查看了如何使用IOS 8创建本地通知。我发现了许多文章,但没有解释如何确定用户是否已设置警报开启或关闭。有人可以帮帮我!!!我更喜欢使用Objective C over 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中是否启用了本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆