3

I have a UIVivewController which inherits UIWebViewDelegate. When I receive at push notification and handle that notification on the Appdelegate. How do I access the webview object to change location of the page.

 class WebViewController: UIViewController,UIWebViewDelegate {

    @IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

     let url = NSURL(string: "WEBURL")
        let request = NSURLRequest(URL: url!)
        webView.loadRequest(request)

        webView.delegate = self
    }

appdelegate

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
webview.Load(userinfo["link"]) //I need to accesss the webview object
}
user516883
  • 8,090
  • 23
  • 68
  • 112

1 Answers1

0

You could try to use:

let vc = self.window.rootViewController as {UIViewController}

Another idea is that you retrieve your already instantiated view controller as a function variable, set / get your property and set is as the presenting view controller.

See this stack overflow post: Opening view controller from app delegate using swift

Community
  • 1
  • 1
Tobonaut
  • 1,859
  • 2
  • 21
  • 36