Always open application at rootViewController - iphone

In my app I want the user to always see the rootViewController's view when the app is opened even if the app has not been killed completely.
One alternative I have considered is calling abort() in applicationWillResignActive: however this doesn't seem like a nice solution.
Any suggestions?

Set UIApplicationExitsOnSuspend in your Info.plist to true.

It appears that you can also set "Application does not run in background" to "true". This is found in the .plist.

Related

How can I completely exit my app when the screen lock button is tapped?

I added UIApplicationExitsOnSuspend to my Info.plist and set it to YES. The key completely exit my app when the home button is tapped.
But how about screen-lock ? or how can I detect screen lock event? There is no key named UIApplicationExitsOnScreenLock I want .
See the clever workaround in this answer. This seems to be the only way to do it but it is a hack, so changes to iOS could make it not work.
Quitting like that is not really appropriate. In your app delegate's -applicationWillResignActive:, just unauthenticate the user, or whatever it is you are trying to accomplish with a full re-start each time. I don't know what steel safe is, but it probably does not quit like that.
Or maybe check for the UIApplicationProtectedDataWillBecomeUnavailable notification? However, it's only sent on device lock if the user has a passcode enabled. If you use NSFileProtectionComplete on your "secret" files, close them when going inactive.

Forcing an iPhone app to quit when Home button is pressed (on iOS4)

I do not want my app to switch to the "task bar" when the Home button is pressed. That's why I would like it to be closed upon Home press. I added this entry to the info.plist file but this does not change the behaviour:
application does not run in background
(and I checked the box...)
I rebuilt the whole app both in debug and release mode but no way. I heard of another key which should be added to the info.plist but I cannot add it through Xcode:
UIApplicationExitsOnSuspend
What is the right way to do that ?
Regards,
Franz
On iOS 4, multitasking is enabled in Xcode projects by default. This prevents the applicationWillTerminate method from being called. If you do not want to support multitasking, place UIApplicationExitsOnSuspend in your MyAppName-Info.plist file and check the checkbox. If you do want to support it, place any code in the applicationDidEnterBackground delegate method that you want to execute before the application enters an inactive state.
What you're doing will indeed stop the application from running in the background, but you can't prevent it from going to the multitasking bar still. Sorry.
You can manually close the application after home button is pressed. When home button is pressed applicationDidEnterBackground is called. In this delegate just write exit(0) and your application will be ended instantly.

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.

Reinitializing iPhone app when it relaunches

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

Is it ok to use exit(0) in "applicationDidEnterBackground:(UIApplication *)application"?

My app crash on exit after upgrade to sdk 4, the error is bad memory access.
I figured that if I put "exit(0)" in "applicationDidEnterBackground:(UIApplication *)application", the app would exit normally.
However, is this ok? This is my only "solution" to the problem so far.
NSZombie is not too helpful this time...
If there's a bad memory access issue, I think the best solution should be to find and fix the memory issue.
However, if you want to stick to the "prevent entering background" way, you should use the appropriate method : disable multitasking. It is described here.
If you do not want your application to remain in the background when it is quit, you can explicitly opt out of the background execution model by adding the UIApplicationExitsOnSuspend key to your application’s Info.plist file and setting its value to YES
Do not put exit(0) in applicationDidEnterBackground:(UIApplication *)application.
Instead, add a key to your Info.plist file to flag that you want the application to exit when it is suspended. For details look at Property List Options.
I find the source of the problem. The problem is that I need to perform all task that affect the interface or views on the main thread. Figuring out this also solved a multiply other bugs that give me headcase. It seems that iOS 4 is more restrictive on thread usage