问题
We do not want to use exit(0) to make the app close, we do however want to allow the app to go to background programmatically and process away, per users allowing this action. Is there a way to send the app to the background programmatically without exit? Simulating the click of the home button?
Thank in advance!
回答1:
Not possible. Home button clicks run into the private GSEvents
framework. It's exit()
or none unfortunately.
回答2:
Is there a way to send the app to the background programmatically without exit?
No. The user is supposed to be in control of the app -- the app shouldn't move to the background (or exit) of its own accord.
回答3:
The below code can be used to send iOS app to background programatically without exit
DispatchQueue.main.async {
UIApplication.shared.performSelector(inBackground:NSSelectorFromString("suspend"), with: nil)
}
来源:https://stackoverflow.com/questions/9970221/send-app-to-background-process