multitask restart app - iphone

My application has setting in Settings.
User may change the setting.
After user apply the changes and launch the app. because the application launched before and it support multitask so the changes applied into the setting, will not apply into the application. Unless the user close the task and relaunch the app.
So I would implement if statement into the application to do:
if (settingBool == 1){
'restarted the application'
} else {
'Multitask keep working'
}
Thanks

You could tell your app that there could be new settings in - (void)applicationDidBecomeActive:(UIApplication *)application
Set a flag or send a notification that tells every object that has cached settings to read them again from the NSUserDefaults

Related

iPhone: Stopping a Program from Running in the Background

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.

Application still running in background Xcode 4.2 iOS 5

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

Auto Log out from an iPhone app (when app goes in the background)

The Settings bundle of my iPhone has the user login and password credentials saved.(similar to the Mail app). The application in its current state does not have a separate login/password view page.
Now, when the app enters the background, I would want it to wait for 40 seconds and after that automatically log off. I found similar posts, and thus found that I could use the methods in the app delegate:
- (void) applicationDidEnterBackground:(UIApplication *)application
{
currentTimeBackground = CACurrentMediaTime();
}
- (void) applicationDidBecomeActive:(UIApplication *)application
{
currentTimeActive = CACurrentMediaTime();
}
Then I plan to use the bottom logic somewhere in my code to trigger a logout.
if ((currentTimeActive - currentTimeBackground)> 40 ) {
NSLog(#"Need to prompt for re login!");
// Logic to logout the application.
}
Now, I found that it is not possible to alter the Settings bundle (.plist) file through a program (at run time). (http://stackoverflow.com/questions/4921890/how-can-i-modify-a-settings-bundle-in-real-time)
So please suggest me how would I log out of this application?
This application fetches data from a server (I have a local server set up for development).
Create a background task and have it wait 40 seconds and then log off. If the user re-opens the app, cancel the background task.

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