Refresh data on entering foreground in all tab bar - ios

I have a small question. I want to refresh (i.e calling web service) my iOS app each time I launch the application and each time the application enters the foreground. And the problem is my app is a tab bar application. And the refresh has to occur in all the tabs.

First, all ViewControllers should be loaded
After, when applicationDidFinishLaunching or applicationWillEnterForeground
for (UIViewController *viewController in rootTabBarController.viewControllers) {
// rootTabBarController = your tab bar
// get all VCs you need.
}
Hope this idea helps you

Related

Is it possible to pop view controller from navigation controller in iOS while the app is in background?

Is it possible to pop view controller from navigation controller in iOS while the app is in background?
I wrote a background task. When I switch my app to background, some code can still be executed but vc.navigationController?.popToRootViewController(animated:false) doesn't have any effect. I'm sure it's executed.
UI Transition is only working in main thread I think.
So, Your pop to root is in background thread.
This may cause your application crash some time.
I think the only solutions is popToRoot when you're about to let your app go to background. Handle the delegate from Appdelegate to do it.

pushViewController doesn't work when app is in background?

I recently refactored an app to use a UINavigationController and pushViewController(...) to transition back and forth between the main UIViewControllers of my app. Previously I was using present(...) with no issues. The app is a music player and has the appropriate background mode.
The transition to view controller B from view controller A happens after a 5 second countdown and thus can happen in the background if the user hits their home button or turns the screen off.
The issue is that the push, and all relevant events that are supposed to kick off when the view did appear, do not fire while the app is in the background, and immediately fire as soon as I turn the display back on or bring the app into the foreground.
Is there any way to force the push to happen even if the app isn't visible, or a different method to push and display the view controller?
Thank for any insight!
let nav = self.parent as! UINavigationController
print("Attempting to .pushViewController...")
nav.pushViewController(sessionVC, animated: false)
print("After .pushViewController...")

SFSafariViewController hides network activity indicator when pushed in a UINavigationController

While SFSafariViewController is loading, we need to indicate to the user a website is loading in the ViewController we've just pushed.
The simplest idea is to turn on the network activity indicator before pushing the new SFSafariViewController and to turn it off in the delegate method once we know the website has loaded. However. when the SFSafariViewController slides in the UINavigationController, it slides over the app, which is fine, but the network activity indicator is not turned on anymore.
No network activity indicator is visible, so we can't communicate to the user that a website is being loaded. We need a way to communicate to the user that a website is being loaded in SFSafariViewController.
I think it's a bug! of iOS 9.
If anybody faced the same issue please tell me how to resolve.
The progress view in the SFSafariViewController is the indicator for a user to know that a website is loading and that is already built in, why would you need another one? If the progress view is hidden because you're pushing add this line to your code, so that you hide the navigation bar:
self.navigationController.navigationBarHidden = YES;

Changing rootViewController in applicaitonWillEnterForeground

Long story short, I'm trying to change my iOS app's rootViewController on applicationWillEnterForeground:, like so:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
MyViewController *controller = [[MyViewController alloc] init];
self.window.rootViewController = controller;
}
However, when iOS performs the "zoom in" animation that is performed when an app is moved from the background to the foreground, it still shows the previous rootViewController's view. Then, as soon as the animation is complete, the app blasts the new rootViewController's view onto the screen.
One way to solve this is to simply move that code to - (void)applicationDidEnterBackground:, but the problem with this solution is that, in my app, there is no way to tell if a new rootViewController will be assigned until - (void)applicationWillEnterForeground:(UIApplication *)application (it is based on time passed since leaving the app).
How can I force the app to redraw before iOS performs the animation taking the app from the background to the foreground?
I believe this is not possible. The screen that iOS shows of your app when it comes into the foreground is actually a screenshot the system took when the app went into the background. There is no way to manipulate or replace that image at the time the app comes back into the foreground.
This behavior is partly documented in the Moving to the Background section of the iOS Application Programming Guide:
Apps can use their applicationDidEnterBackground: method to prepare for moving to the background state. When moving to the background, all apps should do the following:
Prepare to have their picture taken. When the applicationDidEnterBackground: method returns, the system takes a picture of your app’s user interface and uses the resulting image for transition animations. If any views in your interface contain sensitive information, you should hide or modify those views before the applicationDidEnterBackground: method returns.
Apple does not explicitly document that you cannot modify or replace this screenshot at a later time but neither do they say the opposite anywhere I know of.

go to another page in applicationDidEnterBackground in iOS in device

In my application, When the application goes to background I am calling a Passcode page (Passcode Page which does authentication).
My requirement is when the user launch the app from the foreground he will see the passcode page. If he enters the correct passcode then only he can see the rest pages.
In delegate.m file
- (void)applicationDidEnterBackground:(UIApplication *)application
{
PasscodeViewController *passcodeController = [[PasscodeViewController alloc] initWithNibName:#"PasscodeViewController" bundle:nil];
[navController pushViewController:passcodeController animated:YES];
}
When I am launching the application from the background then It is showing me the previous page( from which page I came to background ) for a fraction of second and after that Passcode page comes.
But I want to hide my confidential information from others (who doesn't know the passcode) that are shown in the previous page.
It is correctly working in Simulator but in Device it is not working properly.
Can you please guide me in that ?
OR
Is it the normal behavior of the iOS device ? What ever the page transition it will do, it will perform while the application is running in foreground.
I am not sure about that. Please tell me where I went wrong.
Thank you.
Every app I've used with a similar feature has operated as you describe, with the fractional-second flash before the lock view appears.
I think it's a matter of when UIKit thinks it needs to re-render... We had a similar case with a splash screen, but using applicationDidEnterBackground for adding the splash helped.
My idea is to avoid the animating, using
[navController pushViewController:passcodeController animated:NO];
Whenever your app goes background add a UIView with white background.
Whenever your app comes up push your PasscodeViewController view on top
Please add observers for UIApplicationDidEnterBackgroundNotification and UIApplicationWillEnterForegroundNotification to do the above functionality
Also be sure to remove the Observers when your view disappears
When user enters correct passcode remove the UIView.
Try applicationWillResignActive:
- (void)applicationWillResignActive:(UIApplication *)application
{
PasscodeViewController* passcodeController = [[PasscodeViewController alloc] initWithNibName:#"PasscodeViewController" bundle:nil];
[navController pushViewController:passcodeController animated:YES];
}
When Application goes to background push the passcode viewcontroller to navigationcontroller in the delegate applicationDidEnterBackground because there will be that fractional flash almost all time u can have the passcodecontroller pushed before entering background.

Resources