Bandish Dave
Bandish Dave

Reputation: 811

how to get user's current location when application has been terminated

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?

Upvotes: 2

Views: 740

Answers (1)

Fawad Masud
Fawad Masud

Reputation: 12344

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.

Upvotes: 4

Related Questions