起因
技术栈:Cordova
由于苹果的App Store不再接受UIWebView的代码,必须全部换成WKWebView。因此将cordova-ios的版本升级到了6.1.0
ITMS-90809: Deprecated API Usage - New apps that use UIWebView are no longer accepted. Instead, use WKWebView for improved security and reliability. Learn more (https://deve<wbr>loper.apple.<wbr>com/document<wbr>ation/uikit/<wbr>uiwebview).
报错
结果APP所有访问接口的地方都报错了,连上电脑一调试,发现了Origin null is not allowed by Access-Control-Allow-Origin
报错
问题产生的原因
There are two ways for CORS headers to signal that a cross-domain XHR is OK. One is to send Access-Control-Allow-Origin: * (which, if you were reaching Flickr via $.get, they must have been doing) while the other was to echo back the contents of the Origin header. However, file:// URLs produce a null Origin which can't be authorized via echo-back.(因为cordova运行时是file:// 这样的url,导致发送请求携带的null)
stackoverflow原回答链接
解决
in
CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
afterWKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
add[configuration setValue:@"TRUE" forKey:@"allowUniversalAccessFromFileURLs"];
can fix api fail
github原issue