4

I want to use Background Fetch Location Updates service on my app. But don't show any output my codes here i want your help.

import CoreLocation

class ViewController: UIViewController, UITextFieldDelegate, CLLocationManagerDelegate  {

   var locationManager:CLLocationManager = CLLocationManager()



    override func viewDidLoad() {
        super.viewDidLoad()


        self.locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()


        }

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        print("didChangeAuthorizationStatus")

        switch status {
        case .NotDetermined:
            print(".NotDetermined")
            break

        case .Authorized:
            print(".Authorized")
            self.locationManager.startUpdatingLocation()
            break

        case .Denied:
            print(".Denied")
            break

        default:
            print("Unhandled authorization status")
            break

        }
    }

   func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let location = locations.last as CLLocation!

        print("didUpdateLocations:  \(location.coordinate.latitude), \(location.coordinate.longitude)")


    }

Giving output only

didChangeAuthorizationStatus
.NotDetermined

If it possible i want to take long lat value when new location changes. Thank you !

SwiftDeveloper
  • 6,588
  • 11
  • 50
  • 75

1 Answers1

1

I added this to the info.plist file:

<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message goes here</string>
return true
  • 7,264
  • 2
  • 16
  • 35
SwiftDeveloper
  • 6,588
  • 11
  • 50
  • 75