Location Services still running after app is killed - ios

I am seeing an issue with Location Services still being used by my app even if the app has been killed from the multitasking bar. If I go into Settings > Privacy > Location Services I notice that my app has a purple location icon even while there are NO apps in the background. If I turn off Location Services for my app, the icon in the status bar disappears.
I have ensured in my app that I am stopping location services when they are not needed. I have verified this numerous times in Instruments. GPS turns on when it is supposed to and when the task is finished using location services, the GPS is turned off.
In my applicationWillTerminate: delegate, I even set the lcoationManager to nil, set the delegate to nil and make sure all of that is cleaned up. I still see the icon in the statusbar when I KILL my app.
This particular app also has a bluetooth accessory that can make the app do certain things. So for instance, I press a button on my BLE accessory and it makes the app do something which will trigger a UILocalNotification, so I see a banner. I don't know how to reproduce this particular issue, but I've noticed that even if there are NO apps in the multitask bar and I press the button on my BLE accessory, it will trigger the action in the app and I will see the notification banner.
A few questions:
Has anyone else seen anything like this?
How can I ensure that my app is COMPLETELY killed even though I have cleaned up really good on application terminated?
Why would the location services still be running even though the app is killed. Also keeping in mind that I do NOT use any region monitoring or significant location update changes.
Update:
So I took a previous version of the app and reset Location & Privacy settings and to my surprise, backgrounding the app makes the location icon disappear (as it should have been doing all along. To me this means that iOS is keeping some residual information or settings from the app? Anyone have any insight as to what could be going on here?
Update 2:
Still occurs in iOS 8.1.x.

Related

Questions about app state after tapping on app icon after apps enters suspended state

I’m putting an app into background.
Assuming that I’m not doing anything to keep the app alive in the background, then the app goes through suspended state in a matter of 5 seconds. Right?
What happens if I then tap on the app icon? That’s not suppose to trigger a didFinishLaunch right? It will just bring me back to the last screen I was at and also trigger didbecomeActive & willenterforeground notifications. I won't be getting any other callback. Right?
Assuming there is no restart of the phone, point 2 is true even if there are hours between me tapping home and then tapping back the app icon. Right? Does it also persist device restarts but not force-restart?
The only time I won’t be brought back to the screen I was at (before hitting home) is if the device receives a memory warning and my app is flushed out of suspended state. At this point tapping on the app icon will result in didFinishLaunch. Right?
(I’m asking all of this because sometimes after putting the app in the background and tapping the app icon again (e.g. 10 minutes later), the app is going through it’s launch phase. Most of the time it just goes back to its previous screen)
I've already seen Will ios terminate the app running in background after a specific time? but that doesn't address all aspects I want.
It will just bring me back to the last screen I was at and also trigger didbecomeActive & willenterforeground notifications.
Right, if your app was not terminated in the background.
I won't be getting any other callback.
Not necessarily true. If you were summoned to the front by a local notification, for example, you'll also get an event about that.
Assuming there is no restart of the phone, point 2 is true even if there are hours between me tapping home and then tapping back the app icon.
Not necessarily. The app might well be terminated silently in the background.
Does it also persist device restarts but not force-restart?
Absolutely not. How can the app run when the device is off? Shutting down the app terminates every app.
I’m asking all of this because sometimes after putting the app in the background and tapping the app icon again (e.g. 10 minutes later), the app is going through it’s launch phase
It's not a matter of time. The watchdog process is constantly combing the suspended apps looking for the ones that take up too much memory so that other apps can run. You must not be surprised if yours is one of them.
You can come back to the front launching from scratch or by coming back to life from suspension; it's the most basic fact of iOS app life! You just need to accept it.
But there are lots of things you can do to reduce your chances of being terminated in the background. Giving up memory-consuming objects as you background is first on the list.

iOS: force-closed app restarting in background

We're seeing a strange situation on our iOS app that is impacting our user experience.
When a user background's the app (by pressing the Home button), we can clearly see the app entering the background. When the user then force-closes the app (by double-tappinging the Home button and sliding-up on the app), the app terminates normally. When the app is then re-opened, it follows the normal iOS start-up sequencing.
However, if the user double-taps the Home button while the app is running (resigning the app from active, but not sending it to background) and then force-closes the app (by sliding-up on the app), we're seeing the app terminate (the process gets killed), but then the app immediately re-starts in the background (with a new pid). The app is not designed to start-up or run in the background, and this is causing UX issues.
The app has no entitlements to run in the background, although we do have a couple of third-party libraries that have tasks that wind-down when the app enters the background.
I suspect the issue is a result of the app being force-closed from a non-active state rather than a background-state. If the app enters the background first, the third-party tasks are getting a chance to complete. If the app is force-closed from the non-active state, the tasks never get a change to complete in the background, so iOS is restarting the app in background to give those tasks a change to finish. It's unclear, however, if this is correct behavior.
-Stix
I'm kinda thinking the questions were self-evident, but if not:
Is this correct behavior for iOS? Should iOS be restarting the app in the background when the user force-closes the app w/o putting it into background?
If this is correct behavior, what can cause this to occur? Is it possible some third-party framework - still running a background task that hasn't completed - is the culprit?
The force-close works fine if the app is put into background first (giving background tasks the ability to complete/expire). Is there anyway to force it into background when force-closing the app while it's in a non-active state?

iOS8: How to display blue bar "is Using Your Location" with "requestAlwaysAuthorization"

How does an app register for location services in the background and signification change location services, i.e. using requestAlwaysAuthorization, and get the Blue Bar to warn the user that they might want to end their activity?
According to Apple documentation using requestWhenInUseAuthorization:
The system displays a location-services indicator in the status bar when your app moves to the background with active location services.
However,
Apps cannot use any services that automatically relaunch the app, such as region monitoring or the significant location change service.
The limitation on requestWhenInUseAuthorization seems severe (cannot be relaunched if killed by the OS).
Can an app call both the Authorization methods?
Is the app supposed to forgo being relaunched by significant location change services, in order to get the Blue Bar to be seen?
Am I missing something obvious here?
(Similar question is Blue banner "Your app is using your location" is not showing after exiting my app. Other questions seem to want to get rid of the banner.)
The blue bar only show when you enable Background Location Updates and request when-in-use authorization in iOS 8.
Blue bar “is Using Your Location” appears shortly after exiting app
Sounds like location manager can't stop immediately. So the blue bar will appear until location manager stop completely. Or maybe it's just a bug .

Location services switching off in background in iOS

I have enabled background mode for location services in my app, but when I send the app to the background, it seems that the location services are switched off after a few seconds (the arrow of location services in the device's status bar disappears). I'm not programmatically stopping the location manager, and I'm using standard location service with its best accuracy.
What can I be missing?
Thanks in advance
For iOS 7 and above, When the app is on the background and not executing code. Normally, the system will move app from background mode to suspended mode automatically without any notification. When you app is in suspended mode, you can not do anything (no location update).
In order to keep the app active in the background for iOS 7 and above, you will have to know when to restart the locationManager.
I have a blog post with a detail explanation and also a complete solution uploaded to Github on how to keep the app active in the background, please check this post for more details:- Background Location Services not working in iOS 7

Monitoring Significant Location Changes, App closed GPS signal (Arrow)

First of all I hope don't repeat any topic, I have spent a lot of time reading on internet about this before ask.
I'm developing an app for iOS => 5 and I need get the user location, but I don't need always a great accurate position, so when the app goes to background I change the normal location mode to Significant Location Changes and when the app come to foreground I stop the significant location change mode and get back the normal location mode, that's all goes fine,
my problem is when the app goes to background mode or even the user KILL the app the GPS signal (the purple arrow) still appear ALWAYS, even after restart the device, the only way to make disappear it is un-installing the or disabling the significant location changes when the app goes to background, but I need this mode working when the user goes to background mode, maybe not when the app is killed.
I don't know how to stop the service when the user kill the app... because event "applicationWillTerminate" is not called if you have multitask ON.
My main reason because I don't want the purple arrow appear always, even the app is killed is because I don't want the user think the app is drying the battery... so the user won't want the app installed.
First question: Is normal that the purple arrow appear always, even the app is killed if the Significant location change is enabled for the app?
Second question: Is any way to change this, to stop the service at least when the app is killed to hide the purple arrow?
Thank you all.
Sorry for my english if something is wrong.
After few days researching to be sure about this service, seems like there is NO way to use significant locations change in the background without the arrow in the top bar. I have been testing with different apps and reading through internet and nothing to solve this.
The only ""way to solve"" this is disable multitask mode in the app and disable the significant locations change in the event "applicationWillTerminate" but don't make sense... I'm losing the background location always not only when the app is killed... so is not useful.
It's bad... is a really good service to get locations saving battery but as user and developer I don't want an app that make appear this icon ALWAYS even after the app is killed, as developer I don't want that people uninstall the app for this reason and as normal user I don't know what mean this icon if is normal GPS or Significant locations change and what mean this... if my battery is being drain or not.
The other option to get locations in background task but has a big impact over the battery....
I hope apple fix this in future versions... adding at least a new arrow or showing only when a new location arrive instad of always or allowing to stooped when the app is killed.
All this has been researched over iOS - 6.1
Thanks to all.
When you use the significant location change service, the OS keeps your app running. If the app is in the background and is killed, the OS restarts it, so the purple arrow will always show. When a new location is detected, the app is restarted. From the docs:
If you leave this service running and your app is subsequently suspended or terminated, the service automatically wakes up your app when new location data arrives. At wake-up time, your app is put into the background and given a small amount of time to process the location data. ... To stop the significant change location service, call the stopMonitoringSignificantLocationChanges method.
Hmmm, interesting. I've just seen that problem with another app - seeing the arrow still active made me want to disable location updates for that app so the problem is real. Best thing I can think of is to have some kind of timer to disable the location monitoring after a certain amount of time if that is appropriate for your app.

Resources