Location update even when the application is killed / terminated

I try to get location updates even in all states, even when the application is killed / terminated / paused. I turned on the background selection in xcode and implemented the following code (using the Capture Location link in all state applications ). But when I complete the application, it gives a red line in the AppDelegate class. I do not understand what the problem is. I did this using the solution to the question " Getting space for an iOS application when it is in the background and even killed " here, but it does not work in ios 9. Please help me or tell me another solution.

UPDATED CODE -

class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { var window: UIWindow? var locationManager: CLLocationManager? var significatLocationManager : CLLocationManager? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { if(UIApplication.sharedApplication().backgroundRefreshStatus == UIBackgroundRefreshStatus.Available){ print("yessssss") }else{ print("noooooo") } if let launchOpt = launchOptions{ if (launchOpt[UIApplicationLaunchOptionsLocationKey] != nil) { self.significatLocationManager = CLLocationManager() self.significatLocationManager?.delegate = self self.significatLocationManager?.requestAlwaysAuthorization() if #available(iOS 9.0, *) { self.significatLocationManager!.allowsBackgroundLocationUpdates = true } self.significatLocationManager?.startMonitoringSignificantLocationChanges() }else{ self.locationManager = CLLocationManager() self.locationManager?.delegate = self self.locationManager?.requestAlwaysAuthorization() if #available(iOS 9.0, *) { self.locationManager!.allowsBackgroundLocationUpdates = true } self.locationManager?.startMonitoringSignificantLocationChanges() } }else{ self.locationManager = CLLocationManager() self.locationManager?.delegate = self self.locationManager?.requestAlwaysAuthorization() if #available(iOS 9.0, *) { self.locationManager!.allowsBackgroundLocationUpdates = true } self.locationManager?.startMonitoringSignificantLocationChanges() } return true } func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){ let locationArray = locations as NSArray let locationObj = locationArray.lastObject as! CLLocation let coord = locationObj.coordinate } func applicationDidEnterBackground(application: UIApplication) { if self.significatLocationManager != nil { self.significatLocationManager?.startMonitoringSignificantLocationChanges() }else{ self.locationManager?.startMonitoringSignificantLocationChanges() } } 
+6
source share
1 answer

Check out this tutorial: http://mobileoop.com/getting-location-updates-for-ios-7-and-8-when-the-app-is-killedterminatedsuspended

And the source code is here: https://github.com/voyage11/GettingLocationWhenSuspended

I hope you get an answer. This works for me. Now I'm trying to make an http request when the doUpdateLocations function is called so that I can save the current location of the user on the server when the application is down (paused / terminated / killed).

I do not think that Apple allows any HTTP request when the application is paused / terminated. But if the server received a request to update the location, then I agree with that. Because I do not need a response from the server. It needs a lot of testing ....

0
source

All Articles