CORS 访问控制允许来源 iOS

时间:2021-07-21 09:32:23

标签: angular wordpress-rest-api capacitor

我正在 Angular/Ionic/Capacitor 中开发一个 iOS 应用程序。该应用在 Android 上运行良好,但由于 CORS,服务器调用在 iOS 上被拒绝。

该应用程序使用 WordPress API,其中包括以下功能;

function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');

我尝试在capacitor.config.json 中设置服务器,但没有成功。

也在 config.xml 中尝试了以下内容

<edit-config file="*-Info.plist" mode="merge" target="NSAppTransportSecurity">

config.xml 已经包含

<access origin="*" />
<allow-navigation href="*" />

还是不行?

1 个答案:

答案 0 :(得分:0)

我根据this answer

解决了这个问题

通过添加

add_filter('kses_allowed_protocols', function($protocols) {
    $protocols[] = 'capacitor';
    return $protocols;
});