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.
Related
I'd like my app to do an animation just before close, exactly like the official Camera app from Apple, that "closes the shutter" before closing itself. Is is possible or is this a private and undocumented API?
Thank you in advance!
There is no official way for your app to delay its closing after the user taps the home button. Apple wants users to be able to quit out of apps quickly and at anytime. However, you do get notified when your app is closing, and you do get a chance to run some code. I can't tell you for sure of any UI stuff would work, but the spot to try it is in your UIApplicationDelegate (AppDelegate) class. The methods you're interested in are:
- (void)applicationWillResignActive:(UIApplication *)application {
// Try some UI stuff here
}
Or:
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
I'm assuming the UI will change as the app window is animating away. Let us know if it works!
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;
What is the first method that gets called in the UIApplication Delegate? I have included a launch image in my application, and I would like to get a head start on downloading some data while that screen is still up, before my actual views appear. Should I be looking to place these calls in the delegate, or where is the first place I should think about making these calls?
- (void)applicationDidFinishLaunching:(UIApplication *)application
gets called first.
EDIT:
Your Default.png appears for short time when the app is launched. You cannot rely on this short time to do some processing.
You can show your first view with a message that download is in process (with the help of activity indicator view)
Consider the First answer(as - (void)applicationDidFinishLaunching:(UIApplication *)application called at all first), BUT if you want to display your downloaded image on your first view, then implement some delay (BY Timer or something till your image download), and yeah don't forgot to implement an in between screen with activity initializar(otherwise your application will seem like hanged).
in the new os 4.0 when you leave the application it enter background, but when you relaunch it it doesnt load any code, i want my application to execute a specific method when going back into the app. thanks
You should look into using this delegate method - (void)applicationWillEnterForeground:(UIApplication *)application
More info: https://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/applicationWillEnterForeground:
How can I retain the state of an iPhone after it has exited. What is the easy way to do it?
The first question is when do you save? The answer is in two places (assuming you want to support 3.x and 4.x devices).
First, for OS 3.x devices (and OS 4 devices that don't multi-task):
- (void)applicationWillTerminate:(UIApplication *)application
And second, for OS 4.x devices:
- (void)applicationDidEnterBackground:(UIApplication *)application
You need to do this on iOS4 devices because if the app is shutdown while it's in the background it is just killed; you never see the applicationWillTerminate message.
As for the how, well it depends on how complex your app is. I created a simple protocol that I implement for each view controller that might want to save its state:
#protocol SaveState
- (NSData*) saveState;
- (id) initWithSaveState:(NSData*)data;
#end
It saves the state by looping through view controllers in the main navigation controller and calling the save state method. It then does the reverse in the applicationDidFinishLaunching: method. More information on my blog.
In your application delegate, you can define the -applicationWillTerminate: method to include code to save application state data.
- (void) applicationWillTerminate:(UIApplication *)application {
// save state to data model here...
}
Your data model is up to you. For example, this could be a set of user defaults or a Core Data store.
The next time the app is started, you could check for saved state data in -applicationDidFinishLaunching: and initialize the app appropriately.
If you are using iOS 4 and your application supports multitasking features, you will get some of the state saving functionality "for free" because the app resigns focus, instead of terminating.