【问题标题】:Issue in reading the notification setting in iOS 10在 iOS 10 中读取通知设置的问题
【发布时间】:2017-12-19 13:56:51
【问题描述】:

在我的应用程序中,我使用的是VoIP push。当我尝试阅读通知设置时;我正在获得授权状态notDetermined
但用户已允许推送通知。在 iOS 11 中一切正常。

我正在使用下面的代码:

    if #available(iOS 10,*) {
        UNUserNotificationCenter.current().getNotificationSettings(completionHandler: { (settings) in
            switch settings.authorizationStatus {
            case .authorized :
                NSLog("Setting Value : AuthoRization Status is : authorized")
            case .denied :
                NSLog("Setting Value : AuthoRization Status is : denied")
            case .notDetermined :
                NSLog("Setting Value : AuthoRization Status is : notDetermined")
            }

【问题讨论】:

  • 您是否在代码中使用 requestAuthorization(options:completionHandler:) 请求授权?

标签: swift unusernotificationcenter


【解决方案1】:

notDetermined 表示您的应用从未使用 requestAuthorization(options:completionHandler:) 方法请求授权。

您可能会使用 registerForRemoteNotificationTypes: 而不是 requestAuthorizationWithOptions:completionHandler:

已弃用

  [application registerForRemoteNotificationTypes:
             UIRemoteNotificationTypeBadge|
             UIRemoteNotificationTypeAlert|
             UIRemoteNotificationTypeSound];

新方法:

 UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (bool, error) in }

【讨论】:

  • 它解决了您的问题吗?如果是,请将其标记为答案。它会帮助别人。
  • 它解决了您的问题吗?如果是,请将其标记为答案。它会帮助别人。
猜你喜欢
  • 2017-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-06
  • 2023-03-28
相关资源
最近更新 更多