【问题标题】:My app only asks for push-notifications permission but not for location. How can I fix that?我的应用程序只要求推送通知权限,但不要求位置。我该如何解决?
【发布时间】:2017-09-22 02:24:32
【问题描述】:

在我的应用中,我有这两行:

manager.requestAlwaysAuthorization()
UNUserNotificationCenter.current().requestAuthorization(options: [.sound,.alert], completionHandler: {didAllow, error in}) 

但在加载时,我的应用程序只请求通知权限。如果没有用户允许使用其位置,我的应用程序将无法运行。我怎样才能解决这个问题?

【问题讨论】:

标签: iphone swift xcode push-notification cllocationmanager


【解决方案1】:

我可以假设您已经授予或拒绝了它。要验证它,请尝试运行此代码:

let status = CLLocationManager.authorizationStatus()

然后检测CLLocationManager 的状态,现在您将知道它是什么状态。

如果状态是notDetermined,以this的方式请求权限。

【讨论】:

    【解决方案2】:

    确保NSLocationAlwaysUsageDescription 键存在并且在Info.plist 中有一个字符串值,否则位置权限对话框不会出现

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多