Search code examples
iosswiftcllocationmanagercllocation

didUpdateLocations delegate of CLLocationManager is not called in iOS 11 and Xcode 9.1


Hi have to fetch device current location and for this I am using CLLocationManager class but didUpdateLocations is not calling.

I am

My code and plist are below:

enter image description here

enter image description here

enter image description here

enter image description here


Solution

  • <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>
    

    add this in viewdidLoad

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