2
votes
NSString* jsString = [NSString stringWithFormat:@"alert('ok');"];[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

I wrote it in cordova appdelegate.m!

2
what version of cordova-ios platform are you building with?DaveAlden
cordova -v in terminal -> 5.4.1, but Xcode console display 'Apache Cordova native platform version 3.9.2 is starting.' when I start the app.BskyRui

2 Answers

9
votes

On [email protected] you should be able to do:

[self.webView stringByEvaluatingJavaScriptFromString:jsString];

On cordova-ios@4+ you will need to cast the Webview class as it also supports WKWebView:

if ([self.webView isKindOfClass:[UIWebView class]]) {
    [(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:jsString];
}
0
votes

May want to try NSString* jsString = [NSString stringWithString:@"alert('ok');"];[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString]; or NSString* jsString = @"alert('ok');"[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];