简体   繁体   中英

Call viewcontroller webview method from appDelegate

I've got a webview in my viewcontroller.

I've integrated facebook connect that throws userLoggedIn + userLoggedOut functions from the AppDelegate.m file.

I need to run javascript into the webview from these logged in/out functions, like so: [ _crawlWebView stringByEvaluatingJavaScriptFromString: @"alert('hey ho')" ];

The above line works perfectly from the viewcontroller that holds the webview, but not from appDelegate. What to do?

You need to forward the request from the AppDelegate to the ViewController that owns the WebView.

If that line of code works inside the ViewController

[ _crawlWebView stringByEvaluatingJavaScriptFromString: @"alert('hey ho')" ];

First make sure your AppDelegate has a pointer to your ViewController , and second, make sure that the webView is available through a property.

Then from your AppDelegate you use both the pointer and the property to end up with something like this:

[myViewController.crawlWebView stringByEvaluatingJavaScriptFromString: @"alert('hey ho')" ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM