Right now, I have an application with a single map view. What should I do to stop the app from retrieving new location updates once I hit the home button. My goal is to make that arrow next to the battery symbol disappear when on the main menu page. The app will launch again when the user brings it back to the foreground. This is what I have so far, but it's not working.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
exit(0);
}
What you have should work (in fact, I have used it once for debugging purposes).
However, you should not do that, despite the fact that it works. Simply set the UIApplicationExitsOnSuspend key in the Info.plist file of your application to true.
Related
I have a problem that recognized recently but could not find the solution.Generally when we run an application in simulator we get the following folders:documents,library,tmp,etc.Now if I close the application suddenly in simulator then in library folder we can find caches folder and in that snapshot folder.In this folder we get one folder with bundle identifier name and in that we get screen shot of the application where we closed it.Now my requirement is to stop those screen shots when I close application
You need to hide your view in
- (void)applicationDidEnterBackground:(UIApplication *)application
This is standard behaviour, as it gives the impression that the app resumes quicker if it appears to go back to where it left off - even if technically the app is not quire responsive yet. All you need to do is put something else on the screen in the above method and this will now become the first thing that comes to the front when a user opens your app back up
i wrote an application on the Xcode 4.2 using iOS SDK 5.0.
i have set the UIApplicationexitonsuspend in the info.plist to YES but when i double press the home button, the application is still in the multitasking bar.
i have deleted the app from my iPhone 4s and resend it again from Xcode but still the exit on suspend does not work. application still lingers on multitasking tab.
The fact that your app icon is shown in the "multitask tab" does not mean that your app is still there.
The "multitask tab" simply shows a list of all the apps that you have run.
A simple way to assess if an app is launched anew when you touch it, is by doing the following steps:
launch your app;
close it by pressing the home button;
relaunch the app and inspect the image that it shows on startup. If this image is your "Default.png" image, then the app was launched anew. If you find your app in the state you left it, then the app was simply made active again (i.e., it was in the background).
A more advanced way to see what happens when you launch your app is put an NSLog trace in your app delegate methods:
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
If you will see the traces printed out, then it means that the app was not quit on suspend.
Conversely, you could put a trace in:
- (void)applicationWillTerminate:(UIApplication *)application {
}
if it is called when you press the home button, then the app does not enter the background state, rather it quits.
If you want that your app will not run in background mode. Do the following:-
Open your application info.plist and then add another attribute it it:- "Application does not run in background mode" and make sure that check box is checked for this attribute. Now save , rebuild and run your app again. By doing this your app will not run in background mode.
"Application does not run in background mode" and "UIApplicationexitonsuspend " are the same key
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.
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.
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