Reputation: 3218
Context is ionic/capacitor 6.2 deployed to ios device via xcode.
The basic problem is that a http get (fetch) of an mp3 file completes with a http status code of 0, which is not a valid http status.
I'm fetching a bundle-embedded file (in the /public folder)
example:
const response = await fetch("test.mp3", { method: "GET" });
// response.status should be 200 when the file exists.
I can fetch "/test.txt" and get a http result code 200 and proper content.
When I fetch "/test.mp3" I get http result code 0. A http operation should never return status 0. Still, I can get the content of the file, if I ignore the non-ok result code.
Inspection with safari/developer network tab, security subtab, shows "The resource was requested insecurely" for BOTH requests, although both actually succeeded . I think that this is normal, due to the way the debugger works.
I've investigated and tried NSAllowsArbitraryLoadsInWebContent in Info.plist, but it didn't help (and is disrecommended anyway).
The bad result code is interfering with the operation of a library that I am using.
Explanation?
Upvotes: -4
Views: 67
Reputation: 3218
It turns out that, for fetches of certain media file types (extensions), Capacitor will not preserve the true http status value. Instead, it returns status 0.
This becomes apparent by reviewing the relevant Capacitor code. It's unknown, at time of writing this answer, whether this is intentional or a unintended side effect of changes made to that code in June 2022.
A discussion of the issue can be found on the ionic forum, and a bug report has been opened on github.
Upvotes: -1