Application keeps closing in background mode - iphone

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;

Related

How to set First viewController Screen as a Default opening screen when ever open a app

Hi I am new to iPhone development, I am developing a TabBar app it's contains 5 tabbar Items.
When I am close app at third TabBar viewController screen and again when I am opening app that time same third TabBar viewController screen only opening.
How to set App first screen as a default App opening Screen in iphone.
I need to set first screen as a default opening screen when ever open a app.
Could you please share your ideas here..
When you close the app, it doesn't KILL it, it just suspends it. Unless you set the option to kill it when you close it.
I suggest you read Apple Documentation For Application Flow
And possibly read the other documents Apple have provided for you there if you are new to all of this.
In your application's Info.plist, add a boolean key UIApplicationExitsOnSuspend with the value YES.
This will always exit the app (instead of running in background) when you close it. On opening app again, first view controller will appear instead of where you left it last time.
This is because you are setting your application to be run in background, so whenever you close your app the app will run in background and resume on startUp.
so just do one thing
Go to your info.plist and set value for
Application does not run in background to YES
If application is killed by default it loads all settings in Application Delegate method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Here you can modify your root view controller, which I presume is some kind of tab bar view controller.
So there is probably some code in that method which defines which tab to load.
However if you want to show specific tab after application enters in the foreground use Application delegate method:
- (void)applicationWillEnterForeground:(UIApplication *)application
Or
- (void)applicationDidBecomeActive:(UIApplication *)application
When exiting the app by for example pressing the home button on the iPhone the app is not terminated. Instead the execution is suspended but the app will remain in memory until iOS decides to remove it. This means that when you enter the app again it will be in the same state you left it. You can see if the app is still in memory by doubletapping the home button.
When your app becomes active the method applicationDidBecomeActive: in your UIApplicationDelegate will be called. You can implement that method to set the state you want your app to be in when it is restored.
I would not recommend explicitly killing the app when it is suspended. That forces the app to be reloaded each time it is started which will degrade performance.
For more information see Apple's documentation on app states.

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.

How to handle phone call interrupts in iPhones below iOS 4

In one of my application I need to handle call interrupt. I know application will directly enter background in iOS 4 onwards. How can I handle this situation devices with iOS's less than 4. Do I need to implement any delegate method to be get notified that a call interrupt has come. Please help.
Thanks in advance.. :)
Use the below Appdelegate method:
(void)applicationWillResignActive:(UIApplication *)application
This delegate will call 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 when the user quits the application and it begins the transition to the background state.
To Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. For this use the below appDelegate
(void)applicationDidBecomeActive:(UIApplication *)application
You can have a look at The Application Life Cycle. You will find there the difference between iOS 4.0 and earlier versions.

iPhone Application Themes

I tried using a multi-value settings bundle to change the view. I would do the if statements in the applicationdidfinishloading in the application delegate. Apparently the method isn't called every time the app is loaded, and it would not work correctly.
If anyone has done this, or has any suggestions, links to tutorials. I would really appreciate it. I'm just trying to load views (nibs) based on user preference.
I think you can put your code in
- (void)applicationDidBecomeActive:(UIApplication *)application
or
- (void)applicationWillEnterForeground:(UIApplication *)application
methods also because from iOS 4.0 due to multitasking your app is just in the background state so it wont call applicationdidfinishloading method when the user presses the icon of your app again.

ApplicationWillTerminate in iOS 4.0

The applicationWillTerminate delegate method is not getting called in iOS 4.0
When I hit the Home button I am seeing the applicationWillResignActive and applicationDidEnterBackground delegate methods getting called.
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(#"Application Did Resign Active");
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(#"Application Did Enter Background");
}
And when I double Tap the Home button and again launch the Application the i find the applicationWillEnterForeground and applicationDidBecomeActive delegate methods are getting called.
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"Application Will Enter Foreground");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(#"Application Did Become Active");
}
But I want to know when the applicationWillTerminate delegate method will be called , where I do some DB/file backup routines.
- (void)applicationWillTerminate:(UIApplication *)application{
}
I even tried to hit the minus sign and deleted the App running in the Background , but still it did not call any delegate method.
Any Ideas ???
From the iPhone Application Programming Guide:
Even if you develop your application using iPhone SDK 4 and later, you must still be prepared for your application to be terminated. If memory becomes constrained, the system might remove applications from memory in order to make more room. If your application is currently suspended, the system removes your application from memory without any notice. However, if your application is currently running in the background, the system does call the applicationWillTerminate: method of the application delegate. Your application cannot request additional background execution time from this method.
So yes, applicationWillTerminate: will generally not be called very often in iOS 4. If you have to save data, you should do so in both applicationWillTerminate: and applicationDidEnterBackground:.
The WWDC 2010 Session Adopting Multitasking on iPhone OS (Part 2) explains the application state transitions extremely well.
I got one solution for terminating apps when user hits the Home button in iOS4.
This will call the applicationWillTerminate delegate method instead of entering into background process.
Open your info.plist file
Add The Key UIApplicationExitsOnSuspend
Set the new key to YES
Actually you can also use this step to do so.
Open your info.plist file
Add The Key -> Application does not run in background
Set this key value to YES