wkwebview跨域问题 axios 请求网络返回code 0

wkwebview 的跨域校验更为严格,增加如下配置即可

WKWebViewConfiguration* configuration = [self createConfigurationFromSettings:settings];
    configuration.userContentController = userContentController;

    configuration.userContentController = userContentController;
    configuration.preferences.javaScriptEnabled = YES;
    configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
    configuration.suppressesIncrementalRendering = YES; // 是否支持记忆读取
      [configuration.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"];
       if (@available(iOS 10.0, *)) {
            [configuration setValue:@YES forKey:@"allowUniversalAccessFromFileURLs"];
       }
    WKWebView * w = (WKWebView *)self.webViewEngine;
    NSLog(@"%@",w.configuration.preferences);
    [w.configuration.preferences setValue:@YES forKey:@"javaScriptEnabled"];
    [w.configuration.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"];

猜你喜欢

转载自blog.csdn.net/u010609022/article/details/139285980