Quit app instead of entering background when recei

2019-06-22 10:01发布

问题:

I wonder if it's possible to quit my program entirely after the user presses the Home button, rather than going into background run mode. Thanks.

回答1:

In your application's Info.plist, add a boolean key UIApplicationExitsOnSuspend with the value YES. See the Information Property List Key Reference for more information.



回答2:

Yup!! Although Apple will warn you that they don't want you to do this, it is possible, and I will trust that whatever reasons you have are legitimate. They will not exclude your app from the App Store just because it does not have backgrounding enabled.

In Xcode, find your <-yourappname->-Info.plist file. In Xcode 4, it is located in the "Supporting Files" group. In Xcode 3, it is located in the "Resources" group. Select the last entry and click the "+" icon to add another entry. Type "Application does not run in background" for the key (it will automatically fill this in), and then change the value to "YES".

Good luck with the app!!



回答3:

Refer to this question and its top voted answer for more information on the matter.


Using an Info.plist property UIApplicationExitsOnSuspend you can prevent your app from entering background and terminating as was the norm prior to iOS 4. You can read more about Info.plist keys to learn about additional options.

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