Reset iPhone App - applicationDidEnterBackground - iphone

I'm looking to reset my application completely when it becomes inactive.
I dont want any states retained, is there an easy way to do this?
Would this be done in the Background Method? or any other of the State Methods within the application delegate?

I would suggest disabling iOS 4 backgrounding by adding the key UIApplicationExitsOnSuspend to your info.plist

Related

Application keeps closing in background mode

I have a serious problem in my iphone application. It gets closed after entering in background mode (incoming call or even home button press)...I have inserted UIApplicationExitOnSuspend on info.plist and made its value false. But same problem exists...
Do you have any suggestions for this issue? I really need the application to be suspended not closed when entering to background mode...
Thanks
See in your Info.plist file that you had selected the Application does not run in background, see this option must not be selected, if this option is selected means then remove that option from your Info.plist file, this will surely work I think and I hope this will help you
And Implement these Callback function
-(void)applicationDidEnterBackground:(UIApplication *)application;
-(void)applicationWillEnterForeground:(UIApplication *)application;
in your App delegate
If this application was made from old templates of Xcode 3.x, than it probably don't have methods which used by system to check whether your app handle transitions to/from background or not.
Make sure what this methods implemented by your application delegate:
-(void)applicationWillResignActive:(UIApplication *)application;
-(void)applicationDidEnterBackground:(UIApplication *)application;
-(void)applicationWillEnterForeground:(UIApplication *)application;
-(void)applicationDidBecomeActive:(UIApplication *)application;

how to restart a application without going to recent worked page ,when we exit in ipad

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.

iPhone app startup

How do I make my iPhone app start at the same place each time, i.e. my 'home' screen? I do NOT want the user to return to where they were last time they played - right in the middle of gameplay - but that's what's happening.
Thanks in advance for any tips!
You need to set the UIApplicationExitsOnSuspend key in your info.plist file to YES. Then the app will quit when the home button is pressed, and launch fresh when it is opened again.
This is presumably only happening because your app isn't really being stopped - it's simply being backgrounded. (If you double click the home button whilst viewing springboard does it show up at the bottom? If so, it's still running.)
You can disable this behaviour (so your app quits when the user hits the home button) by setting the UIApplicationExitsOnSuspend key (known as "Application does not run in background" within Xcode) in your info.plist file. See Apple's Information Property List Key Reference docs for more information.
Alternatively, you could simply capture the applicationDidEnterBackground: UIApplicationDelegate method in your app's add delegate and handle the situation from there programatically. (i.e.: Do whatever you need to do to reset your app back to the 'home' screen, etc.)
- (void)applicationWillResignActive:(UIApplication *)application {
[self.navigationController popToRootViewControllerAnimated:YES];
}
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
Set UIApplicationExitsOnSuspend to YES int the Info.plist.

Is it possible to get ivars with startMonitoringSignificantLocationChanges in backgrounded mode

When an app uses startMonitoringSignificantLocationChanges while backgrounded or when terminated, if a significant change is detected Apple states that it will bring the app back into the foreground. But, will I still be able to get the value of an ivar (previously set when the app was in the foreground) within the didUpdateToLocation CLLocationManager delegate method? Or is it lost?
If it is lost, what is the best way to persist those values after the app has terminated/backgrounded and brought back into the foreground by the location manager?
Yes of course you will. The only way you'd lose the value of that ivar is if your app has actually quit and been relaunched, at which point you're not simply coming back from the background.

quit app in iOS4

I have an old app which did many UI initialization work in viewDidLoad of various views. In iOS4 home button just put the app in background so viewDidLoad won't get called when re-launching the app.
I don't want to put those initialization procedures in viewWillAppear as it is unnecessary to re-initialize the data every time the view appear.
How can I completely quit my app when user press the home button? or any simple way to reload the view controllers that sit inside a tabBarController?
thanks.
There is a key in your app's Info.plist file called UIApplicationExitsOnSuspend, set it to the boolean YES, which will essentially revert the home button's functionality to pre-iOS4 and completely exit your app when the home button is tapped.
Try disabling backgrounding. Apple has this in their documentation
Try to check.
UIApplicationExitsOnSuspend
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html
you have to look up to the UIApplicationDidBecomeActiveNotification i think, but in the uiapplicationdelegate-protocol, there are even some other interesting things for you
or perfectly for you:
UIApplicationWillEnterForegroundNotification as a new notification in ios4 for this problem