I have an old app which did many UI initialization work in viewDidLoad of various views. In iOS4 home button just put the app in background so viewDidLoad won't get called when re-launching the app.
I don't want to put those initialization procedures in viewWillAppear as it is unnecessary to re-initialize the data every time the view appear.
How can I completely quit my app when user press the home button? or any simple way to reload the view controllers that sit inside a tabBarController?
thanks.
There is a key in your app's Info.plist file called UIApplicationExitsOnSuspend, set it to the boolean YES, which will essentially revert the home button's functionality to pre-iOS4 and completely exit your app when the home button is tapped.
Try disabling backgrounding. Apple has this in their documentation
Try to check.
UIApplicationExitsOnSuspend
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html
you have to look up to the UIApplicationDidBecomeActiveNotification i think, but in the uiapplicationdelegate-protocol, there are even some other interesting things for you
or perfectly for you:
UIApplicationWillEnterForegroundNotification as a new notification in ios4 for this problem
Related
My app uses multiple features for Apple's demo project AVCam. Everything works just fine except when I exit the app and go back in it, it doesn't show the camera preview anymore. Does anyone know what piece of code I am supposed to use and where it belongs? I tried searching but a lot of questions relating to android popped up.
You need to reinitialize your camera once the App becomes active again. In your app delegate methods, override, applicationDidBecomeActive and send a notification so your view controller knows that your app became active again.
Pending the notification received, you can reload the viewDidLoad, or move the contents of viewDidLoad to viewDidAppear. There's multiple ways to do this. You can also reload the contents of viewDidLoad in viewWillAppear. There's many many many ways to do this, like I said.
I am using xcode4.2 and inside appDidFinishLaunching i am initializing navigationController with my first view and sets the rootViewController of app to navigationController.I want to show the first view every time when app resumes. How i can i do this?
The easiest way I can think of is not using backgrounding. If you set the UIApplicationExitsOnSuspend key in Info.plist, when the user press the home button, your app will quit and next time it is launched it will start over and not resumed from where it was.
Otherwise, you can define – applicationWillEnterForeground: and – applicationDidBecomeActive: to go back to your first view whenever the app is resumed. Have a look at the UIApplicationDelegate reference and Multitasking states.
I have traced a problem in my iPhone app code to the viewDidAppear method not always firing. When you start the app the event fires as expected. However if I close the app using a phone capable of multitasking and reopen in. My viewDidAppear events no longer fire.
My views are loaded from Nibs and I use viewDidUnload to clean up (release and nil all outlets). My views are nested in side and tab bar then navigation controllers. I looks like the events aren't wired up properly when the nibs reload. Any idea on what I'm doing wrong/missing and how I can fix this?
Thanks in advance.
UPDATE I do not mean the event is not fired when the app first comes into the foreground. I mean the event never fires again. Even when changing between tabs or moving though the navigation views.
Example:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(#"viewDidAppear called");
}
This code is placed in two views, each on different tabs. Each time I swap between tabs "viewDidAppear called" is written to the log. When I close and reopen the app and swap between tabs this no longer happens. Other button events fire normally.
Btw, the viewDidUnload method is really badly named btw -- it's not an 'opposite' to viewDidLoad, it's only called if there was a low memory situation and the view for that controller was unloaded due to not being visible at that time.
(ORIGINAL, NOT SO RELEVANT ANSWER:)
Please see my answer to this similar question:
Why does viewWillAppear not get called when an app comes back from the background?
Basically, viewDidAppear gets called after your UIViewController's view was added to the application's UIWindow heirarchy. Backgrounding then restoring the app doesn't change your view in that respect, so viewDidAppear doesn't get called -- it's correct behaviour, and not a bug. Check out the API docs for UIViewController.
Found it.
While not new to programming I am new to iPhone development. On researching this problem I found it was not recommended to call the viewWillAppear and viewWillDisappear methods manually.
My viewWillDisappear methods resign any keyboards if shown, when my app enters the background it loads a splash screen ready for when the app re-enters the foreground (there is some logic I need to do to work out what the user is shown on restarting the app and I can do this under the splash screen).
As viewWillDisappear is not called when the app goes into the background to make sure no keyboards appeared over my splash screen I was calling viewWillDisapper in the applicationDidEnterBackground method. I guess this also un-registers my events.
By adding viewWillAppear to my applicationDidEnterForeground method my events started firing again. Lesson learned, I will refactor this so I don't call these events manually.
Thanks for the help.
I am developing an iPhone application (iPhone with multi tasking support) in which I am displaying UIAlertView on error. When UIAlertView is about to get display my app is sent to background. Now, if I try to get my app in the foreground, UIAlertView gets displayed for a moment and gets dismissed automatically even if I don't call dismiss/click on any button.
Does anyone knows what the problem is?
Thanks and Regards,
Deepa
When you add an alert view, it is added on top of the view of the current viewcontroller and while coming back to foreground , sometimes the view is reloaded from the xib and all the contents are refreshed. I suggest you to maintain a state variable in controller which calls the alertView again when coming back to foreground.
Rajact answer is good if by 'call' means the next
[theViewWhenYouAddedIt bringSubviewToFront:theViewWhenYouAddedIt.theAlert];
This worked for me
I hope this helps someone
When my Iphone-App was already running and I try to go back to it then it cannot refresh or reload the news or tables automatically.
How could i set an automatic refresh on the quickstart of the App?
Thx
To add to the previous answer, you can do this in your app delegate's applicationWillBecomeForeground: method, which is called when your app is about to be returned to the foreground.
There's also the UIApplicationWillEnterForeground notification, which you can sign up for to allow any object (like a view controller, for example) to be notified when the app is about to return to the foreground. Either technique should get the desired effect.
You can try go call code to do that like : [self.tableView reloadData]; or [self.myNetwork reloadNews];