How to prevent an iPhone app from closing until all activity is done
My app communicates wirelessly to an external device. I want to prevent the user from closing the app until a response is received from the device, which can take a few seconds.
In the ViewController.viewWillDisappear and also the appDelegate.applicationWillTerminate I can put logic to see if there is still something left to do, but I can't determine how to keep the app from closing anyway!
I recognize that the 'performance' of the phone will look bad if the app doesn't close quickly, but I would put up a view explaining to the user that the app must complete before shutting do开发者_开发技巧wn AND be patient.
Anyone know of a way to do this?
Sorry, you can't prevent the app from quitting. If you try to stop the app from quitting, the iOS will terminate your program.
With iOS 4.0, you can have tasks that are allowed to complete in the background. Check out: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
For an overview about running tasks.
This was also answered in User can't quit the iphone application?
You can't, the OS intentional prevents such behavior. Your app is terminated if it doesn't shutdown within a certain timeout after being told the user hit the home button.
精彩评论