2

I have gone through many tutorials but not able to find the right solution. I am working on location base application where I need to fetch user's current location, it doesn't matter even if the application is running in foreground or in background. So when i kill or terminate the application is it possible to fetch user's current location?

Bandish Dave
  • 791
  • 1
  • 7
  • 27
  • use signifigant monitoring update location -- it shows the last object of the location – Anbu.Karthik Jul 08 '15 at 06:53
  • possible duplicate of [How to Get Location Updates for iOS 7 and 8 Even when the App is Suspended](http://stackoverflow.com/questions/27742677/how-to-get-location-updates-for-ios-7-and-8-even-when-the-app-is-suspended) – Anbu.Karthik Jul 08 '15 at 06:59
  • 1
    @Anbu.Karthik i have been following your suggested link from last two week, and also download the demo code from github and installed in my ipad but its not working. i want to call webservice in didUpdateLocations method but it is never called when app is terminated. can you please help me how can i do that? – Bandish Dave Jul 08 '15 at 07:09

1 Answers1

4

Yes it is possible. You will have to use method startMonitoringSignificantLocationChanges. According to CLLocationManager documentation

If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives. In such a case, the options dictionary passed to the application:didFinishLaunchingWithOptions: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the location property of your location manager object is populated with the most recent location object even before you start location services.

Fawad Masud
  • 12,219
  • 3
  • 25
  • 34
  • thank you for replay.... i followed http://mobileoop.com/getting-location-updates-for-ios-7-and-8-when-the-app-is-killedterminatedsuspended this link from last two week...but didFinishLaunchingWithOptions and didUpdateLocations is never called......i am testing on my ipad... can you please help me when this two method is called – Bandish Dave Jul 08 '15 at 07:20
  • didFinishLaunchWithOptions is called when an app is launched. It has nothing to do with location services. Check Privacy > Location Services of your ipad if location services are enabled for your app or not. Also from ios8 you need to get permission from the user to use location services. – Fawad Masud Jul 08 '15 at 07:29
  • yes i have already gave permission for location and location service is enable in my ipad.... let me know which method is called when application is terminate so i will call continuesoly my webservice in that method. – Bandish Dave Jul 08 '15 at 07:37
  • - (void)applicationWillTerminate:(UIApplication *)application is called in app delegate on app termination. – Fawad Masud Jul 08 '15 at 07:40
  • i mean my application is already terminated then where how can i code for webservices to upload the lat long to the server continuesoly? applicationWillTerminate this method only called once when application is terminated. – Bandish Dave Jul 08 '15 at 07:47
  • You have to write the code in -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { } – Fawad Masud Jul 08 '15 at 07:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/82675/discussion-between-bandish-dave-and-fawad-masud). – Bandish Dave Jul 08 '15 at 08:07