Can we get user current location when app is not running in iOS? - ios

We would like to track user so we want user current location when app is not running also.
We are tracking user when app is in background or foreground mode but in some cases like battery drain, memory footprint issue etc, app going to auto kill so in that case we can not track user. We have used startMonitoringSignificantLocationChanges also but in this case we are getting user location once user moved around 500 meter or more from their current location. If user not move after app kill, we can not track. Is there any way to do this?

Certain types of apps, like turn-by-turn navigation apps, are allowed to run from the background, and can continue to monitor the user's location.
Normal apps cannot. If the system terminates your app you stop receiving location updates. As you say, you can use startMonitoringSignificantLocationChanges or geofencing to get updates when the device moves a significant distance, but I don't think there is another solution for an app store app.
("Kill mode" isn't really a meaningful term.)

Related

iOS 10 update location when app is terminated

I'm making an app where I am showing the User's distance from other users. I'm able to update user locations when app is open and when app is in background HOWEVER I can not figure out how to update the location when app is terminated. I have been told that this is not possible but I believe it is possible because Life 360, Facebook, etc update the location in terminated state. Any help on how to achieve this is greatly appreciated!
To do this you need to use:
myLocationManager.startMonitoringSignificantLocationChanges()
From the docs:
"If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives."
Unfortunately from extensive testing the significant changes when they start to come through are very inaccurate so you may wish to switch on normal location updates at the point you receive a significant location change in the background.
myLocationManager.startUpdatingLocation()

iOS: How to use location tracking during predefined time period while saving battery life?

iOS: How to use location tracking during predefined time period while saving battery life?
I need to activate location tracking during predefined time periods (does not matter if app in background or foreground) and need to be sure that battery life is not impacted too much?
PS:
Please not that running location in background with tracking significant changes does not suits because it gives you location after 10 min and only when you passed reasonable amount of distance ... so during driving 40 km I got location only 3 times that will not allow me to catch user movement near some point. If running location more often ...that drains battery upto 40 percent per 6 hours...
I've researched all background modes in iOS very thoroughly recently.
The only deterministic way that will allow you to do that, without location background mode are silent pushes.
You send a silent push to the user and the user returns a location.
You could also use background fetch. But it's very non-deterministic. You can't predict if it indeed will wake up your app, or not.
EDIT:
Please note, that this will not wake up the app that was forcefully terminated.
However, the system does not automatically launch your app if the user
has force-quit it. In that situation, the user must relaunch your app
or restart the device before the system attempts to launch your app
automatically again.

Initiate location capture at a particular time even if the app is in background or not running

Is there any way in latest iOS to initiate location capture at a particular time each day (say morning and evening ), even if the app is in background or not running.
You should read Background execution. Background jobs are actually not recommended:
An app might move to the background because the user launched a different app or because the user locked the device and is not using it right now. In both situations, the user is signaling that your app does not need to be doing any meaningful work right now. Continuing to run in such conditions will only drain the device’s battery and might lead the user to force quit your app altogether.
As for getting user location check this answer How can I get current location from user in iOS

Why location icon remains on even if I killed foursquare from background

I had done loads of R&D on locations services and I come to know that if you kill app from background then there is no way you can get location update.
but now I observed even if I kill Foursqure from background it still uses location services as location icon is present on the top, Once I turn off location services for foursquare location icon gets disappeared from top.
please guide me how foursquare do this?
Apps can register to get deferred location updates. This means that the OS can accumulate location data and feed it to the app later when the program is launched. Perhaps this is what's going on with Foursquare?
From Apple docs:
In iOS 6 and later, you can defer the delivery of location data when
your app is in the background. It is recommended that you use this
feature in situations where your app could process the data later
without any problems. For example, an app that tracks the user’s
location on a hiking trail could defer updates until the user hikes a
certain distance and then process the points all at once. Deferring
updates helps save power by allowing your app to remain asleep for
longer periods of time.

Getting user's location while making a phone call

I need to get exact location (as much accurate as possible) in background while making a call to a phone number (The call will be made from app). As far as I understand from documentation, I can listen to significant changes of location in background. I am wondering how accurate is a significant update and when will it trigger.
I need the location where the call is made because it will be an emergency call. And it's not a good idea to listen to location in foreground and then make a call because it will be an emergency situation - call will be made immediately.
Is there a solution to get accurate location of user in background? What do you recommend?
Edit: Location will be sent to server immediately.
As for the accuracy, you can get accurate location in the background, under those conditions:
Getting Location Events in the Background
If your application needs location updates delivered whether the application is in the foreground or background, there are multiple options for doing so. The preferred option is to use the significant location change service to wake your application at appropriate times to handle new events. However, if your application needs to use the standard location service, you can declare your application as needing background location services.
An application should request background location services only if the absence of those services would impair its ability to operate. In addition, any application that requests background location services should use those services to provide a tangible benefit to the user. For example, a turn-by-turn navigation application would be a likely candidate for background location services because of its need to track the user’s position and report when it is time to make the next turn.
As for getting location during phone call, I didn't use it myself, but navigation apps like 'waze' do inform turns and navigation events during a phone call so I guess what you ask is possible.
If I understand your needs, you have 2 options:
If you think that the user will be static then simply get the user location right before the call is made. Or better when your app is lunched to make the emergency call.
If the user is moving then you can 'ask' to get background location events. Even then you should consider using 'significant-change location service' as you don't need more then the user location. The standard 'location services' are used for navigation 'Turn by turn' services.
*LAST COMMENT *
If your app is an emergency app you shold read the "Tips for Conserving Battery Power" in the previous link. you don't want your user battery to empty while tracking his location.
Can't you like add that flag in your app plist file to request Location Service to be running in the background mode.
Then in your app, when the user presses the "call" button, you can do your normal CLLocationManager didUpdateToLocation, right before you perform the call.
In your didUpdateToLocation method, you can record the user's location either in a TXT file written to the application sandbox Library/Cache folder or you can use NSUserDefaults.
Note: I've written an app that records the user's GPS location as they drive even when the user presses the lock screen, so I am confident your app can write the GPS coordinate to a TXT file even when the app is minimized, as long as you start your location manager.

Resources