2

My Goal is to send data from iOS device to WkWebView. After researching on how to do this task I get to know that it can be done via executing JavaScript function via WkWebView, therefore, I tried calling just a simple alert function:

@interface UIWebViewController ()  <WKNavigationDelegate, WKUIDelegate>



@end

WKWebView *webView;

-(void)webView:(WKWebView )webView didFinishNavigation:(WKNavigation )navigation{

    NSString* javascriptString = @"alert('Hi');";
    [webView evaluateJavaScript:javascriptString completionHandler:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
    webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
    webView.navigationDelegate = self;   

}

Unfortunately I am not able to see any alert with that code?

Can you let me know what kind of silly mistake I am doing in the above code?

6
  • Possible duplicate of iOS WKWebView not showing javascript alert() dialog Commented May 6, 2017 at 19:51
  • The problem is not the calling of the JavaScript, but that alert() doesn't show if you don't implement the delegate, see the link above. Commented May 6, 2017 at 19:51
  • I have already implemented WKUIDelegate to my controller. Commented May 7, 2017 at 2:00
  • and does runJavaScriptAlertPanelWithMessage get called? Commented May 7, 2017 at 2:02
  • I don't have any reference to runJavaScriptAlertPanelWithMessage in my code. Commented May 7, 2017 at 2:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.