Frage

I am using core location framework inside my application and I set the location string in UIBackgroundMode or Required background modes(in Xcode 4.2) for getting the updated location from didUpdateToLocation method when app is running in background and also sending this updated location to server by hitting the specific link inside didUpdateToLocation method of core location framework.

My question is that will the app be terminated after some time when running in background or not?

War es hilfreich?

Lösung

No, there is no specific time defined for this.But app will definitely terminate based upon certain parameter - battery drain, memory footprint issue etc.

In developer documentation it is clearly mentioned - "The system keeps suspended apps in memory for as long as possible, removing them only when the amount of free memory gets low. Remaining in memory means that subsequent launches of your app are much faster."

Go through this for complete details - http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

Andere Tipps

I am sure it is not useful for the author because the question was asked in June 2012 and I am giving an answer in June 2019. This answer maybe is useful for other users.

I am posting this answer because Everyone is said that it is OS default behaviour, We can not change it....bla....bla.

Recently, I was working with the same requirement. After 2-3 week hard work, I did it. For other users, I create a helper class for it. My app will never be killed by OS until the location tracking enabled.

You can also verify that OS will never kill this app tracking app

Use HSLocationManager for infinite location tracking in the active and inactive state.

Refer my app which is available in the app store(App will never kill by OS if location tracking is enabled)

Location manager that allows getting background location updates every n seconds with desired location accuracy.

Advantage:

  • OS will never kill our app if the location manager is currently running.

  • Give periodically location update when it required(range is between 2 - 170 seconds (limited by max allowed background task time))

  • Customizable location accuracy and time period.

  • Low memory consumption(Singleton class)

iOS app may get terminated due to following reasons:

  1. Watchdog Timeout

As you’re probably aware, since iOS 4.x, most of the time when you quit an iOS app, the app isn’t terminated – instead, it’s sent to the background.

However, there are times when the OS will terminate your app and
generate a crash log if the app didn’t respond fast enough. These
events correspond with the implementation of the following
UIApplicationDelegate methods:

   - application:didFinishLaunchingWithOptions:
   - applicationWillResignActive:
   - applicationDidEnterBackground:
   - applicationWillEnterForeground:
   - applicationDidBecomeActive:
   - applicationWillTerminate:

In all of the above methods, the app gets a limited amount of time to finish its processing. If the app takes too long, the OS will terminate the app.

  1. User Force-Quit

iOS 4.x supports multitasking. If an app blocks the UI and stops responding, the user can double-tap the Home button from the Home screen and terminate the app.

Note: You may have noticed that when you double-tap the Home button, you also get a list of all the applications you’ve run in the past. Those apps are not necessarily running, nor are they necessarily suspended.

Usually an app gets about 10 minutes to stay in the background once the user hits the Home button, and then it gets terminated automatically by the OS. So the list of apps that you see by double-tapping the Home button is only a list of past app runs.

  1. Low Memory Termination

When subclassing UIViewController, you may have noticed the didReceiveMemoryWarning method.

Any app that is running in the foreground has the highest priority in terms of accessing and using memory. However, that does not mean the app gets all the available memory on the device – each app gets a portion of the available memory.

When total memory consumption hits a certain level, the OS sends out a UIApplicationDidReceiveMemoryWarningNotification notification. At the same time, didReceiveMemoryWarning is invoked for the app.

At this point, so that your app continues to run properly, the OS begins terminating apps in the background to free some memory. Once all background apps are terminated, if your app still needs more memory, the OS terminates your app.

I have seen that the background location updates will work for several hours. But if I go to a place without reception the device will stop to send GPS updates it wont start when I go to a place with reception. This occurs after approximately 30min.

But if I add this, in iOS6, the app won't terminate

[locationManager setPausesLocationUpdatesAutomatically:NO];

Quick answer is pretty much no. Read below though for in depth.

Since multitasking has been enabled on iOS devices that a)your app gets allocated amount of memory and b)the device limits the amount of tasks, that is applications using memory, that occur at any given time. If you take an iOS device and open several apps you'll begin to notice that the app you opened first may have been terminated and reload from the viewDidLoad.

Generally it's safe to say if your app is a recently opened app (or even on a phone where someone clears the multitasking menu often) that the device will not terminate your application in the background.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top