gpt4 book ai didi

ios - WKWebView 崩溃 iOS9

转载 作者:行者123 更新时间:2023-11-29 01:08:04 24 4
gpt4 key购买 nike

我在模拟器上使用 WKWebView 时遇到未知错误。一个 friend 用他的 Iphone 得到了同样的结果。当我从 Web 服务器加载页面时,我尝试单击页面内的按钮,但 webView 崩溃并且我在屏幕上看到一个空白页面。这不是 JavaScript 问题。

我发现了类似的问题,但没有解决方案。 (有人提到 CGRectMake 或 32/64 位兼容性...)

我的代码在这里:

 - (void) webView:(WKWebView *)webView didFailLoadWithError:(NSError *)error url:(NSString *)url {

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc]
init];

WKUserContentController* userController = [[WKUserContentController alloc]init];

[userController addScriptMessageHandler: self name:@"musique"];
[userController addScriptMessageHandler: self name:@"upload"];
configuration.userContentController = userController;

self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20) configuration:configuration];

[self.view addSubview:self.webView];
NSLog(@"ici web");
// Setup WKUserContentController instance for injecting user script




[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];



}

提前致谢

最佳答案

问题是由于再次执行函数 addScriptMessageHandler 引起的,您应该将以下代码放在函数 viewDidLoad 中:

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc]
init];
WKUserContentController* userController = [[WKUserContentController alloc]init];

[userController addScriptMessageHandler: self name:@"musique"];
[userController addScriptMessageHandler: self name:@"upload"];
configuration.userContentController = userController;

self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20) configuration:configuration];

[self.view addSubview:self.webView];
NSLog(@"ici web");
// Setup WKUserContentController instance for injecting user script

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];

关于ios - WKWebView 崩溃 iOS9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36112563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com