WEB开发网
开发学院手机开发iPhone 开发 iOS 4中禁止程序退出后保留在后台的方法 阅读

iOS 4中禁止程序退出后保留在后台的方法

 2010-09-15 23:56:00 来源:WEB开发网   
核心提示:只需要在plist中加入UIApplicationExitsOnSuspend。Opting Out of Background ExecutionIf you do not want your application to remain in the background when it is quit, you c

只需要在plist中加入UIApplicationExitsOnSuspend。

Opting Out of Background Execution

If you do not want your application to remain in the background when it is quit, you can explicitly opt out of the background execution model by adding the UIApplicationExitsOnSuspend key to your application’s Info.plist file and setting its value to YES. When an application opts out, it cycles between the not running, inactive, and active states and never enters the background or suspended states. When the user taps the Home button to quit the application, the applicationWillTerminate: method of the application delegate is called and the application has approximately five seconds to clean up and exit before it is terminated and moved back to the not running state.

Opting out of background execution may be preferable for certain types of applications. Specifically, if coding for the background may require adding significant complexity to your application, terminating the application may be a simpler solution. Also, if your application consumes a large amount of memory, the system might need to terminate your application quickly anyway to make room for other applications. Thus, opting to terminate, instead of switch to the background, might yield the same results and save you development time and effort.

Note: Explicitly opting out of background execution is necessary only if your application is linked against iPhone SDK 4 and later. Applications linked against earlier versions of the SDK do not support background execution as a rule and therefore do not need to opt out explicitly.

Tags:iOS 禁止 程序

编辑录入:coldstar [复制链接] [打 印]
赞助商链接