Application restarts when waking up from background

G'day iOS Guru,

I searched many times for an answer, but I can’t find it (I’m sure the first answer to my question will be to another similar question, but I can’t find it).

In any case, my problem is that I am launching a simple card application that the user can discard on the card using a custom circle superimposed around the discarded output.

When the application enters the background mode (iphone is locked or the home button is pressed), if I restart the application again within ~ 5 minutes, the pins are still present and the application reopens on the last screen.

Things are good.

However, if I leave the application in the background for more than 5 minutes, the application will restart and all contacts will be lost.

I have “Application does not work in the background = NO” in plist, and also included “Application registers for location updates” in the “Required background modes” section.

How can I prevent the application from restarting after it enters the background and loads the last open view?

+4
source share
2 answers

iOS can and will terminate your application when it is in the background, if it needs additional resources to complete everything that happens in the foreground.

You need to make sure that your data is saved / archived when your application is completed, and unpacked upon restart to return to the place where the last user was. The traditional way to do this is to use the applicationDidEnterBackground method, which is called when your application is paused. Then you can save all the data necessary in order to resume cleaning if your application is completed.

However, if you focus on iOS 6 and above, you can use the new function - Presumption and restoration of state (link to documentation) . Government recovery disables some (but not all) of the hard work on iOS and can automatically reduce your user interface and provides easier ways to save and restore data.

+2
source

in AppDelegate.m

 - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // Save your data } 
0
source

Source: https://habr.com/ru/post/1484157/


All Articles