简体   繁体   中英

App launched from the first screen from the foreground ios

When I pressing "home" button, app calling - (void)applicationWillResignActive:(UIApplication *)application , ok its good, but when I wait for a some time (10-15 mins), app starting from first loading screen, why? I have added:

[UIApplication sharedApplication].idleTimerDisabled = YES;

But not success. I think it goes to suspended mode, how do I prevent this? Thanks.

It means that your app has been killed by the system. You can't prevent it completely, the system kills background apps when it needs more memory, but you can do something like this:

  • free as memory as you can when the app goes in background: doing this, when the system needs memory, your app won't be one of the first to be killed because its footprint is low.
  • Since you can't be sure that your app won't be killed, use state preservation / restoration: Link

EDIT:

since your app needs to reproduce audio in the background (as written in the comments) I give you some extra advices.

  • remember to register your app background mode (from this link: Multitasking guide ) --> "by including the UIBackgroundModes key (with the value audio) in its Info.plist file"
  • the app continues to work in the background since it's playing audio, but when the audio is suspended the app is suspended too (it means that it can be killed). So, you must use state preservation to restore it when the user comes back.

Another extract: "When the UIBackgroundModes key contains the audio value, the system's media frameworks automatically prevent the corresponding app from being suspended when it moves to the background. As long as it is playing audio or video content, the app continues to run in the background. However, if the app stops playing the audio or video, the system suspends it."

You app has exited. If you want it to come back to where you left off you'll have to preserve the state somehow, check on launch, and then restore the state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM