Reinitializing iPhone app when it relaunches - iphone

I am building an iPhone app. Currently when I close the app and relaunch it, it relaunches on the last viewed view. Instead I want to be able to reinitialize the app, and present the view that's most appropriate for the application's state (based on what's in the database).
How can I do that?

You have two options. You can follow Petesh's suggestion to make your app always terminate, or you can implement -applicationWillEnterForeground in your app delegate and reset things there.

I presume it's iOS4 - your app is not being terminated in this case, it is merely being suspended.
You need to follow the instructions here: http://maniacdev.com/2010/07/screw-multi-tasking-how-to-make-your-ios-4-apps-exit-for-real/ which will terminate the app when the user presses the home button.
You need to add the appropriate 'correct view' logic to your application's start-up code once you've done this.
For the purposes of expediency, I'm adding the instructions here:
Open your info.plist file
Add The Key UIApplicationExitsOnSuspend or Select Application does not run in background
Set the new key to YES or Fill in the tick box

Related

iPhone - Sending the app to the background

In my app, when it runs for the first time, it shows a UIViewAlert and offers you to see the preferences for the app - and the user has 2 choices - yes or no. If the user hits no the alert fades away and the application continues running. I want to set it in such a way, that if the user hits yes, my app will go to the background, the settings tab of the app will be opened (I added a settings bundle to the app). Is it possible to do such a thing? Thanks!
No, this is not possible. But you can create a settings view in you app and show it instead of trying to open the settings app.
Normally, you do want to encourage users to use your app as long as possible, and making them quit your app yourself is not the best way to achieve that.
No, this isn't possible.
But you could use InAppSettingsKit and modally show a view controller with the settings inside the app.
You can find out more here - http://www.inappsettingskit.com/

Can we write the action for Home button in iphone

I am going to develop an application which will be posted in cydia. My requirement is after unlocking the iphone when the user clicks the home button then my application need to be popedup(run) ..
is it possible to do this?
if yes how?
You can do this without any extra code by changing the settings in Activator. The app doesn't need to be in Cydia, either.
Confirm you have Activator installed from Cydia.
Go to the Settings app, followed by Activator.
Choose which environment you want the action to run in: Anywhere, Home Screen, in an app or Lock Screen.
Scroll down to “Home button” and tap the action you want.
Scroll down again, until you see the app you want. Tap it and confirm there is a check mark next to it.
Now your app will start every time the action occurs. If you want this to be automatically set when your app is installed, however, you'll need to include the libactivator header in your code and use its API to set the action. Because the header isn't included with iOS, you'll need to make the app for Cydia.

iPhone: What is the correct way to leave an Application?

Hallo Everyone,
with the iOS 4, the iPhone is supporting Multitasking, what is very nice, but something I do not wish to support in my Application. I mean, when the user press the Home-button, I want my application to finish and not to enter in Background. With the iOS 4, when the User press the Home-button, the App calls the applicationDidEnterBackground: delegate's method to enter in Background and in order to "force" the Application to finish when the user press the Home button, I've done following implementation:
- (void)applicationDidEnterBackground:(UIApplication *)application {
//save everything...
exit(0);
}
PROBLEM: I've noticed, that exit(0) brings the Application immediately to finish, without calling deallocating methods like "dealloc", and I think that is not a good programming style. So I would like to ask you guys, how to bring the application to finish in a "nicer" way.
Thanks in advance.
What you actually want is not to exit the application (which is as mentioned not allowed), but tell the OS you would rather your application be killed rather than backgrounded.
There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated.
That's two questions:
How to programmatically exit an iPhone app - duplicate
Proper way to exit iPhone application?
How to cause an iPhone app to not go to background in iOS4:
Add the UIApplicationExitsOnSuspend key to your info.plist and set its value to YES
http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
One answer above says "There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated." with Xcode 4, the info.plist value is "Application does not run in background" of type Boolean, so setting this to YES will have the app exit when the user presses the "home" button.
You are not allowed to. I know from experience: got an app rejection from Apple because I've exited (that was two and a half years ago but I doubt they've changed their policy here). There's a "private" (i.e. not mentioned in header file) method "terminate" on UIApplication, IIRC. But Apple says you may not do that. Only thing you can do is to show a dialog, asking the user to press the home button. But in turn doesn't work if on a device with multitasking enabled... so I guess you really have to change your application in such a way that you can throw away your state on applicationDidEnterBackground and start afresh on application on applicationDidBecomeActive.

iPhone app remembers last state (multitasking?) unwanted behavior!

User launches the app, quits, relaunches and the app shows up in the exact previous state, as if the app didn't quit at all. I have no custom save state support, so this is really baffling. It happens on one of the user's 3GS, but not on my 3G. Which seems to indicate that this is OS4's multitasking at work, because 3G isn't supported. If this is true, is there a way to turn off this behavior?
So, if your app isn’t supposed to use multitasking at all or if you simply wish to disable it during development or debugging, all you’ve to do is to edit your project’s info.plist and depending on how you’re editing it:
* Raw text editor
Add a property named “UIApplicationExitsOnSuspend” and set it’s value to ‘Yes’
* The XCode GUI plist editor
Add a new row and select “Application does not run in background” (or type “UIApplicationExitsOnSuspend”) and then toggle the checkbox
http://www.alexandre-gomes.com/?p=545

When i kill the application in multitasking bar,and run the program it's goes to same state where i was closing the app

Today i updated my 3GS i-phone to install my application to see it's functioning well in OS4,when i'm running the application and tap the home button it's goes to multitasking bar,then again i get the application from there it's goes to previous state where i was.i think the behavior is OK. but problem comes when i kill the application in multitasking bar and run it it's come to same state,simply it's ignore the login screen.
My question is when i kill the application i want to get my login screen, not the previous state, this application is working fine in 3GS,can some one please help me to fix this issue?
Thanks
Sam.
Sam,
If you don't want the OS to save state for you, you should place the key UIApplicationExitsOnSuspend in your info.plist file.
More information here: http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
This will kill the app when the home button is pressed, instead of suspending it into the background (which is what iOS4 does for multi-tasking).