self.nflWebView = [[WKWebView alloc] initWithFrame:self.view.bounds];
self.nflWebView.backgroundColor = [UIColor clearColor];
self.nflWebView.opaque = NO;
[[self nflWebView] setDelegateViews: self];
self.nflWebView.tag = 10000;
[self.nflWebView loadHTMLString:html baseURL:[NSBundle mainBundle].bundleURL];
[self.view addSubview:self.nflWebView];
我还尝试了另外一些事情:
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
{
NSLog(@"stringByEvaluatingJavaScriptFromString");
NSLog(@"script :%@",script);
__block NSString *resultString = nil;
__block BOOL finished = NO;
WKWebView *obj_wkwebview=[[WKWebView alloc]init];
[obj_wkwebview evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
if (error == nil) {
if (result != nil) {
resultString = [NSString stringWithFormat:@"%@", result];
}
} else {
NSLog(@"evaluateJavaScript error : %@", error);
}
finished = YES;
}];
while (!finished)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
return resultString;
}
它给出错误。
Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo=0x170c788c0 {NSLocalizedDescription=A JavaScript exception occurred}
简单的html内容正在加载成功但是没有加载带有javascript的html。
我做了很多谷歌搜索,但没有成功。如果你有任何其他方法来做这件事,请建议我。 提前谢谢。