在loadHTMLString之后uiwebview冻结了

时间:2017-07-20 23:11:34

标签: ios objective-c uiwebview timeout connection

我有一个本地HTML文件,我使用WKWebView来加载我的viewController。站点显示在应用程序内部后,站点上的每个功能(例如滑块)都会冻结整个应用程序。只有这条消息出现了:

  

Connection :: waitForSyncReply:等待回复时超时

我的代码:

        NSData *fileData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FlowPage" ofType:@"html"]];
        NSString *htmlString = [[NSMutableString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];

        NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";

        WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
        WKUserContentController *wkUController = [[WKUserContentController alloc] init];
        [wkUController addUserScript:wkUScript];

        WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
        wkWebConfig.userContentController = wkUController;

        _wkWebView = [[WKWebView alloc]initWithFrame:self.view.frame configuration:wkWebConfig];
        _wkWebView.UIDelegate = self;
        _wkWebView.navigationDelegate = self;
        _wkWebView.translatesAutoresizingMaskIntoConstraints = NO;
        _wkWebView.clipsToBounds = YES;


        dispatch_async(dispatch_get_main_queue(), ^{
            [_wkWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"https://www.icarros.com.br"]];
        });

        [self.view addSubview:_wkWebView];

显示该网站显示为我的本地存档,但所有数据的交互或过程都在中间丢失。他无法在服务器端执行任何操作。

0 个答案:

没有答案