在iOS 11和Xcode 9.1中未调用CLLocationManager的didUpdateLocations委托

时间:2017-12-20 10:51:32

标签: ios swift cllocationmanager cllocation

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

我的代码和plist如下:

enter image description here

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分: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()