2

I met strange case during my test. My application should work on background (it updates location). When I test update location on simulator everything works fine I can see information printed in console, but when I test on device plugged to Mac nothing happen, I can't see any information on console.

Can you explain what is exactly happening? Why test background mode on device didn't work?

To test update location I use GPX files.

Below my code for update location:

func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {

    if !self.locations.isEmpty {
        distance += newLocation.distanceFromLocation(self.locations.last!)
        print("distance \(distance)")
    }
    self.locations.append(newLocation)

    if UIApplication.sharedApplication().applicationState == .Active {
        if let currentDest = navigationCoordinator.coordinates.first as CLLocationCoordinate2D? {
            mapView.clear()
            updateViewMapWith(newLocation.coordinate, destLocation: currentDest)
        }
    } 
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
LakaLe_
  • 454
  • 1
  • 6
  • 15
  • Now that you know about Background Modes, you don’t need to make the same mistake as before! Check the box for Location updates to let iOS know that your app wants to continue receiving location updates while in the background. – iOS Developer Jan 07 '16 at 12:26
  • @iOSDeveloper Location update is checked and nothing change. I still can't test location update in background on my device – LakaLe_ Jan 07 '16 at 12:33
  • try this http://rshankar.com/get-your-current-address-in-swift/... – iOS Developer Jan 07 '16 at 12:43
  • This helps me fix my problem http://stackoverflow.com/questions/30808192/allowsbackgroundlocationupdates-in-cllocationmanager-in-ios9/30821461#30821461 – LakaLe_ Jan 07 '16 at 12:58

0 Answers0