Continue location updates after iOS device is rebooted - ios

In iOS7, will an app that has requested continuous location updates (not signification changes/ region monitoring) be relaunched after a reboot?
When I reboot my phone, the app is suspended, then terminated. When I restart my phone, the app stays in the terminated state until I manually start it.
I've tried adding a background fetch with minimum refresh intervals to relaunch the app, but that's never called either.
In the apple doc it explains that if I enable significant location changes, it will launch my app from a terminated state, but does not mention anything about continuous location updates.
Any recommendations on how to get my app to continue receiving updates after relaunch?

I don't think this is going to be possible because its no use if your app launches in the background anyway because the monitoring for location updates initial request HAS to be made while your app is in the foreground.
If this request is made while the app is in the background then it doesn't work. You somehow have to get your app into the foreground so you can start the process of getting updates again.
You could add significant location changes temporarily as an experiment so that your app gets woken up and then see if you can get location updates once your app has been launched into a background state but I'm 99% sure you won't be successful.

I have tested for many months, the only possible way for iOS to relaunch the app for new location updates after the app is terminated/suspended is using the locationManager method startMonitoringSignificantLocationChanges. If you use startUpdatingLocation, iOS will not relaunch the app for you and hence the app can not get the location update.
If you want to understand the details about the differences between getting location update in the background vs getting location update even when the app is kill/terminated/suspended, please see:-
A) Getting location update when the app is In the background, please see: Background Location Services not working in iOS 7
B) Getting location update when the app is suspended/terminated, please see: How to Get Location Updates for iOS 7 and 8 Even when the App is Suspended
I have written 2 very long article explaining the different between the 2 scenario. The source codes for the above 2 scenario are also available on the GitHub.

Related

How can we get updated location after app is terminated?

We have used
significantLocationChange(https://developer.apple.com/documentation/corelocation/getting_the_user_s_location/using_the_significant_change_location_service)
for update location but it gives location update sometimes and so it
is not consistenly giving the location update.
What is the best way to get updated location frequently when app is
in terminated stage (not in foreground / not in background)
You have to enable Background modes for Location updates for your app. You can do this by selecting your Project -> Capabilities -> Background Modes and enable Location updates.
There is no way to do that, IMHO. If the app is terminated you will get no frequent updates, it was the users choice to terminate your app and Apple respects this. iOS does not collect location data in the background and handles it over to your app when your app is started again.

Do location services not update on someone elses test iPhone?

I am not getting background updates on another test iPhone. I have an application built and running fine on my own test iPhone. The simulator works fine as well with testing. Both can keep pulling the location services while in the background. I test this by spitting the lat and long into the debug area. Even when in the background, both spit the lat and long and keep chugging through.
When I put it on my roommates iPhone to test it, it does not keep updating in the background. Other than that, it works fine. I went into the development part in his settings and could not find anything there either. Is there something I am missing with allowing an the app to run in the background?
Go to Settings -> Privacy -> Location Services (should be ON) -> Name of your app (check if you allow using location)
Check Background App Refresh setting in Settings/General
Apple - getting the user's location
When a user disables the Background App Refresh setting either
globally or for your app, the significant-change location service
doesn’t relaunch your app. Further, while Background App Refresh is
off an app doesn’t receive significant-change or region monitoring
events even when it's in the foreground.

Background fetch is not working after killing the app

I'm trying to get data from url with background fetch. My func tries to get data and if there is a new data, it sends local notification. Background fetch works after about 10 - 20 minutes when i minimize the app. But when i kill the app (double click home button and close app) it doesn't work. I waited about 1 hour but it didn't work. I am using background service in android and it is working successfully. Is there any way to get data from url and send local notification when app is closed? I am using Xcode 6 and swift 1.2
The Background Fetching will NOT happen in your app after the user has killed it in the multitasking UI. This is by design.
Take a look at Apple's documentation that mentions:
Apps that support background execution may be relaunched by the system
to handle incoming events. If an app is terminated for any reason
other than the user force quitting it, the system launches the app...
and
In most cases, the system does not relaunch apps after they are force
quit by the user. One exception is location apps, which in iOS 8 and
later are relaunched after being force quit by the user. In other
cases, though, the user must launch the app explicitly or reboot the
device before the app can be launched automatically into the
background by the system.
As you noticed in the documentation, there's only 1 exception when the app will be relaunched if it was force killed: by using location services. Unfortunately this does not apply to you.
Also, you cannot detect if the app was force killed by the user. Check this StackOverflow answer.
The Background Fetching will NOT Update in your app after the user has killed app from background. it is not Possible

cordova getting Location Updates for iOS 7 and 8 when the App is Killed/Terminated/Suspended

I'm working on a cordova application which needs to get location updates and send them to a server even if the device is in sleep mode. I can track the location of a device if the app is on foreground and also background with my version now. But after 10-15 minutes the app gets killed by OS and I no longer get any location updates until the user launches my app again.
Well in my search of finding a solution to this problem I found this article:
http://mobileoop.com/getting-location-updates-for-ios-7-and-8-when-the-app-is-killedterminatedsuspended
It shows how to get location updates even if the app gets killed. The main problem is that I'm not really sure that this could work with a non-jailbreaked iOS and I've never wrote a cordova plugin myself before.
So is it possible to track location and send those through socket.io or http to a specific server?
Or at least to write those geolocation updates in files which I would send when my app launched?
If the answer of my first question is yes: How should the plugin look like?
#Kingalione,
you can keep the App from being killed. There was a documentation error in Apple's documentation. Here is my blog post on this:
Slight Documentation Error causes Background Operations Issuehttp://codesnippets.altervista.org/blog/2015/BLOG.2015-07-02.jssnippets.html
To apply this fix, you'll need to add to your .plist file. Unfortunately, I do not know how to do this for the Cordova CLI. Here is the section that you need for UIBackgroundModes

Is there a way to know if and why iOS terminated your app?

I'm trying to debug an issue with my iPhone app that seems to be getting terminated while running on the device (it never happens in the simulator). The app is for iOS 8 only.
Once app enters the background (via the user hitting the home button) I start Significant-Change Location service. When a location updates happens while the app is suspended the system should put the app in the background where I then send an update to my server with the location. That operation is wrapped in a proper beginBackgroundTaskWithExpirationHandler to allow me the time needed to make the network call.
It appears though my app is getting terminated by the system because sometimes when I resume the app from the suspended state it is no longer in the view last seen when minimizing but is back at the root controller as if starting from a fresh launch. It does not appear to be due to a crash as I do not see it in the crash log nor is New Relic reporting such. The app is suspended though, not terminated, probably because it is getting launched again into the background from a location update.
The question is, is there a way to know that my app was indeed terminated by the system, and if so, for what reason(memory, exceeding background execution time, etc.) and at what time. Is there a log kept somewhere containing this information?
I'm under the impression I can not use applicationWillTerminate because the docs say this is not called when an app is suspend.
You may check in Devices page. (Shortcut is Command + Shift + 2)

Resources