如何查询UIUserNotificationSettings类型

Sam*_*io2 11 permissions notifications objective-c ios ios8

我正在尝试实现application:didRegisterUserNotificationSettings:App Delegate方法来尝试识别我是否被允许向iOS 8中的用户发送本地通知.以下是我想要实现的那种事情,但这显然是不正确的方式走吧.

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{

    if (notificationSettings.types /*How do i check which types are contained */) {

        NSLog(@"Allowed");

    } else {

        NSLog(@"Not Allowed");
    }

}
Run Code Online (Sandbox Code Playgroud)

Bhu*_*hta 23

干得好

if (notificationSettings.types == UIUserNotificationTypeNone) {
      NSlog(@"Permission not Granted by user");
}
else{
      NSlog(@"Permission Granted");
}
Run Code Online (Sandbox Code Playgroud)

询问特定设置:

BOOL allowsSound = (notifSettings.types & UIUserNotificationTypeSound) != 0;
Run Code Online (Sandbox Code Playgroud)

  • 啊,好吧......就像这样:`BOOL allowSound =(notifSettings.types&UIUserNotificationTypeSound)!= 0;`` (2认同)