How can I prevent an application from exiting immediately? If the user press the home button while the application is saving a picture to the photo album, only a part of the picture is saved!
Thanks!
You can't. You can put code in your App Delegate's
- (void)applicationWillTerminate:(UIApplication *)application
Function to attempt to quickly finish saving the picture and notify the user that they prematurely quit the application, but there's nothing you can do to prevent a user from pressing the home button and quitting your app.
Related
I have an app with multiple View Controllers. I have a Home screen with "Play / Options / etc.". When you hit Play, you navigate over to the GamePlay View Controller and start playing.
I find that if I'm in the "gameplay" VC and I hit the iPhone's Home button (leaving my app) and then re-launch my app, it puts me right back to the game screen. I'd like to force the app to start on the same "Home" screen every time is it launched.
Suggestions greatly appreciated!
Thanks,
-Ed
in your app's plist add the key UIApplicationExitsOnSuspend and set it to YES.
Your app wont be suspended and youll always start on the home screen
When you press the Home button, the application goes to background. When launched again, application just enters foreground from background. I think you can load the home screen in the following delegate method in AppDelegate
- (void)applicationWillEnterForeground:(UIApplication *)application
You can preserve the state of the game (I don't want to kill that zombie again!) in the following:
- (void)applicationDidEnterBackground:(UIApplication *)application
I just want to show an alert when user just quit the application before application entering the background, how can I do that??
If I show the alert in applicationDidEnterBackground:(UIApplication *)application method then this alert will be shown when we again resume the application, but I need to show the alert before the application enters the background.
You can't do this, and rightly so. When the user presses the home button, they go to the home screen. This is a fundamental part of the iOS user experience. Nothing stops the home button working.
applicationWillResignActive and applicationWillTerminate may be of interest to this general question—but you can't present anything into the UI once the home button is pressed. These methods do let you briefly run any critical code however, while the home screen is being presented to the user.
I had installed my app on ipad(ios 4) , and i was navigating through the pages of my app.whenever i close the app and re open the app it goes back to the recent page which i was working on.
But i want it to restart the app from first page,whenever i exit and reopen .As it is working on iphone(ios 3.1.3),Can any one suggest how to do that on ipad.
thanks in advance
I think you can do that easily. You need to set info.plist key "Application does not run in background" to YES and it will no longer to run in background.
When application enters background the delegate method appDidEnterBackground is called and when resumed the method willEnterForeGround will be called.
You can handle your application behaviour in these methods.
For more info you can refer to this link which explains the concepts beautifully.
On iOS 4 the app does not exit it goes to background. And when you tap on the icon the app resumes from where you left it.
If you want to reset something when it goes in background you need to implement custom code in appDelegate methods:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}
You need to set UIApplicationExitsOnSuspend to yes in your info.plist
Which methods are called when user presses home button and double presses it again to return
here you can find answer to event on clicking on home button
interesting article
Find your info.plist file in resources and add the key:
"Application does not run in background" and set the value to 1.
When the iphone home button is pressed, it will only hide the user interface but any process currently running will keep on running at the background. I find that if the process is still running, when i activate the app again, the splash screen will be displayed for a long time until the process is completes before it display the main page of the app. Is there a way to terminate the processes when the home button is pressed?
1) For example, if I have a for loop and before the loop finishes, the home button is pressed, is there a way to terminate the loop?
2) What if instead of a loop, its a delegate waiting for the sdk function to finish the process.
eg. After calling UIImageWriteToSavedPhotosAlbum to save an image, didFinishSavingWithError will be called when it finish saving. Can i terminate the saving process whe the home button is pressed?
Thanks.
You can try adding a new row in the info.plist of your application and select "Application does not run in background" or write "UIApplicationExitsOnSuspend"
Do as Aluminum said.
Not to do 1, but add the following method to the app delegate
(void)applicationDidEnterBackground:(UIApplication *)application
and do something in the method like exit(0)
When my app is run in the iPhone simulator, the delegate method
- (void)applicationWillTerminate:(UIApplication *)application
is only called the first time I hit the iPhone simulator's home button.
After the home button is pressed and the app is launched again, hitting the home button does not call the delegate method.
What is going on here? Am I misunderstanding something fundamental?
I suspect that it is being called, but that you are getting confused because after you hit the Home button in the Simulator, you've ended the current session in Xcode. You probably have an NSLog in your applicationWillTerminate: method, yes? Once you hit the Home button, NSLogs no longer show up in Xcode's run console. If you open /Applications/Console.app I expect they'll show up there.
- (void)applicationWillTerminate:(UIApplication *)application
is called when the application "terminates".
If you are using iOS then the app will NOT terminate when the home button is pressed, unless you have disabled multi-tasking for your app or the user does not have a "multi-tasking supported" device.
- (void)applicationDidEnterBackground {
is now used when the user presses the home button. Unless (as I previously said) you have disabled multi-tasking for your app or the user does not have a "multi-tasking supported" device.