WKWebView无法触发ajax在本地加载文件

chi*_*k10 6 ajax wkwebview ios9.1

我将所有html嵌入到WKWebView中,一直有效,直到我认识到WKWebView无法在本地加载xml文件


$.ajax({
        type: "GET",
        url: "tags.xml",
        dataType: "xml",
        cache: false,
        success: function(xml) {

        },
        error: function() {

            alert("An error occurred while processing XML file.");
        }
    });

我的UIWebView代码

//urlFolder is located locally in a temporary file: tmp/www/htmlFolder 
//urlFile is located in the urlFolder: tmp/www/htmlFolder/index.html
//xml file is located in the urlFolder: tmp/www/htmlFolder/tags.xml


WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
    _webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
    [_webView loadFileURL:urlFile allowingReadAccessToURL:urlFolder];

    [self.view addSubview:_webView];

注意:我使用的是XCode7.1 Beta,Objective-C,ios9.1,WKWebView

Dir*_*oer 3

据我所知,他们在 WKWebViews 中禁用了跨域请求。

搜索 cors 或 xhr + WKWebView 以获取有关此问题的更多信息。我认为这一定是某种错误,因为这在使用本地文件的“正常” UIWebView 中始终是可能的(如您的示例)。

不过,您可以在应用程序中运行一个小型/轻量级的 http 服务器,这对我来说非常有用。App Transport Security Settings确保在 .plist 文件中为 localhost添加例外。