【问题标题】:didUpdateLocations delegate of CLLocationManager is not called in iOS 11 and Xcode 9.1 [duplicate]在 iOS 11 和 Xcode 9.1 中未调用 CLLocationManager 的 didUpdateLocations 委托 [重复]
【发布时间】:2017-12-20 10:51:32
【问题描述】:

您好必须获取设备当前位置,为此我正在使用 CLLocationManager 类,但没有调用 didUpdateLocations。

我是

我的代码和plist如下:

【问题讨论】:

  • locationManger?.delegate = self 设置在 viewDidLoad 中?
  • @InderKumarRathore 是的,但是当我在 viewWillAppear 中设置委托时仍然无法正常工作。
  • 您是否向用户请求了位置信息? locationManager.requestWhenInUseAuthorization()locationManager.requestAlwaysAuthorization()
  • 尝试实现 didFailWithError 方法以确保它没有失败

标签: ios swift cllocationmanager cllocation


【解决方案1】:
<key>NSLocationAlwaysUsageDescription</key>
    <string>Requires GPS to track persons</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Requires GPS to track persons</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Requires GPS to track persons</string>
    <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>location</string>
    </array>

在 viewdidLoad 中添加这个

locationManager.delegate = self
   self.locationManager.allowsBackgroundLocationUpdates = true
   self.locationManager.startUpdatingLocation()

【讨论】:

  • 我使用了这个代码。但还是不行。
  • @ajeetsharma 删除应用并再次运行
  • 谢谢!!它的工作:D(y)
猜你喜欢
  • 1970-01-01
  • 2011-11-29
  • 2016-05-07
  • 1970-01-01
  • 2014-09-20
  • 1970-01-01
  • 1970-01-01
  • 2016-05-12
  • 2015-10-01
相关资源
最近更新 更多