programmatically prevent app from running in background iOS
I have an app that will run in the background but there is one case where I do not want that to happen, can I achieve this programmatically?
I know I can opt out by changing this plist value but what about at run time?
4 Solutions Collect From Internet About “programmatically prevent app from running in background iOS”
You can’t use exit(0) b/c apple does not allow you to close the app without user knowing it.
From Technical Q&A QA1561 How do I programmatically quit my iPhone application?.
There is no API provided for gracefully terminating an iPhone
application. Under the iPhone OS, the
user presses the Home button to close
applications. Should your application
have conditions in which it cannot
provide its intended function, the
recommended approach is to display an
alert for the user that indicates the
nature of the problem and possible
actions the user could take – turning
on WiFi, enabling Location Services,
etc. Allow the user to terminate the
application at their own discretion.
Add the variable UIApplicationExitsOnSuspend (Application does not run in background) to your applications plist and assign the value YES.
You can close the app by calling
Calling exit() is discouraged, and not informing the user that the app is going to terminate is also discouraged. So you need to get the OS to kill your app (as it normally would do over a long enough period of operation) while simultaneously informing the user. One way of doing this, while using only legal APIs, is to dirty absolutely as many memory pages as possible (malloc and bzero), then call Safari with a URL to a hoggish website explaining why the app is going to quit. Safari will require enough memory to display the website that your app will be terminated by the OS, just as the user is being properly informed.
Sleeping until the OS kill timer kills your app will also kill your app, but this non-responsive delay will lock up the UI, which isn’t a good user experience.
- Color alternate UITableViewCell in a UITableView?
- Objective-C. Property for C array
- How to change UITextfield placeholder color and fontsize using swift 2.0?
- Check if iOS app is in background
- Search through a large json file for a particular key value pair
- Keep iphone active while running program
- New iTunes connect interface error “You must choose a build”
- What is the best way to connect Realm and SwiftBond
- dyld: Library not loaded: @rpath/Alamofire.framework/Versions/A/Alamofire Reason: image not found
- NSAttributedString superscript styling
- Segue – index 0 beyond bounds for empty array
- Can you do custom animations for UITableView Cell Inserts?
- Received memory warning and app crashes
- How do I create a CGRect from a CGPoint and CGSize?
- UIButton at bottom of screen only intermittently highlights