【问题标题】:Not to ask for permission for notifications in iOS but add "notification permission settings" into device settings?不是在iOS中请求通知权限而是在设备设置中添加“通知权限设置”?
【发布时间】:2016-12-17 19:04:15
【问题描述】:

我不想显示“请求通知权限”对话框,只是将我的应用程序的禁用设置添加到设备设置中。

问题是如果应用程序不请求这些权限,那么相关设置根本不会出现在设备设置中。

我调用权限对话框的代码:

UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

您能帮忙解决这个问题吗?目前我只使用本地通知

【问题讨论】:

  • 您需要申请通知权限才能让该部分进入设置
  • 这件事你别无选择,必须显示弹窗

标签: ios permissions notifications uilocalnotification localnotification


【解决方案1】:

我在我的应用中使用它来接收推送通知:-

// Let the device know we want to receive push notifications
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }

【讨论】:

  • Man registerUserNotificationSettings: 调用一个请求权限的对话框。目前我的应用没有远程通知,但似乎registerForRemoteNotificationTypes: 将通过相同的方式工作。
  • 1)它不会起作用,因为UIUserNotificationTypeSound 从 iOS 8 开始可用。2)registerForRemoteNotifications 将立即调用通知权限对话框,但问题是如何避免此对话框
【解决方案2】:

根据Apple 文档,您必须在第一时间请求用户许可。因此,为了进行设置,您必须至少询问用户一次。

【讨论】:

  • 好的,谢谢,我希望我可以在没有此对话框的情况下创建禁用设置。例如,当您在设备设置中为您的应用程序添加设置时 - 您只需创建它们而无需额外的对话框。
猜你喜欢
  • 1970-01-01
  • 2012-10-12
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-17
  • 2017-07-31
相关资源
最近更新 更多