Refresh a view from AppDelegate class RRS feed

  • Question

  • User335007 posted

    Hi Everyone. Could someone help me with and issue if it is possible. In my iOS app I have registered a URL type in the info.plist file, so if I click a specific url on the phone it will launch my app. This is working, What I am doing is when the url is clicked and the app is launched, I do some server comms in the public bool OpenUrl method which adds an item to my app. I need to refresh the view controller to display that item now. Currently I have to kill the app and relaunch it, then I can see the item.

    Is there a way to get an instance of the view controller in the AppDelegate.cs class and do a refresh or even just to get an instance so that I can call a method in the View Controller from the AppDelegate class?

    Any help will be appreciated. I have been searching online, but have not found any suitable solution yet.

    Thank you


    Thursday, October 12, 2017 5:23 AM

All replies

  • User159595 posted

    It is possible to get the visible view controller from the AppDelegate.

    var window= UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; If (vc.PresentedViewController != null) { vc = vc.PresentedViewController; }

    You can also add an event to the AppDelegate that your view controller can subscribe to and update UI accordingly.

    Saturday, October 14, 2017 6:09 PM
  • User335007 posted

    @JasonFeinkind Thank you, I managed to call methods in my ViewController using the following:

    this is in my override bool OpenUrl method in appdelegate.

    UIViewController root = this.Window.RootViewController;
    ViewController vc = (ViewController)root.ChildViewControllers[0];

    In my View controller I handled refreshing after new dynamic data came back from server.

    Monday, October 16, 2017 8:14 AM