Lona
October 1, 2021, 7:56am
1
I’ve got a problem with Axios I think. It’s working fine in the browser, on Android it’s fine, but on IOS it just stops.
In Xcode I’m getting:
Loading app at capacitor://localhost...
WebView Loaded
To Native -> App addListener
I’m pulling data from a WordPress Site (I control it) and I’ve tried to add “capacitor://localhost” for the preflight handle (CORS) but to no avail.
I’ve added “*” for access control in order to test it as well, but doesn’t work.
So, curious, If I need to set some settings in the Info.plist or similar in order for it to work.
I’m pulling data locally (json file) with Axios and that works fine on IOS.
Lona
October 2, 2021, 7:34am
2
I´ve also added capacitor://localhost, but it just is not working. It works fine on the android device. And it´s definetly a CORS problem as indicated by the Safari developer console.
[Error] Failed to load resource: Origin capacitor://localhost is not allowed by Access-Control-Allow-Origin. (posts, line 0)
Lona
October 2, 2021, 7:38am
3
I´ve got this on my wordpress site:
$allowed_domains = array(
...
'https://localhost:8100',
'http://localhost:8100',
'capacitor://localhost'
);
if (in_array(strtolower($origin), $allowed_domains)){
// header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Origin: $origin");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Authorization, Content-Type,Accept, Origin, origin");
header("Content-Type: application/json; charset=UTF-8");
status_header(200);
exit(0);
}