Open jmarshall-com opened 2 years ago
I managed to work around this by using blob:
URLs for all displayed images:
let blob= new Blob([await read_file_binary(file_entry)]) ;
img.src= URL.createObjectURL(blob) ;
... where read_file_binary()
reads a file as an arrayBuffer. Note that the Content Security Policy must include blob:
in the img-src
directive.
This isn't as efficient as just using file:
URLs, but it's much better than using data:
URLs. It does seem like a bug in either cordova-ios
(?) or in WKWebView (?), but I'm set for now.
I managed to fix a similar error with this snippet
if (device.platform == 'iOS'){ var loc = window.WkWebView.convertFilePath(store + bannerDir); }
I guess this might work for your let full_url
or just install the ionic webview plugin which provides a way to access files using the same url scheme as the app uses working around this problem.
Issue Type
Description
UPDATE 3: I managed to work around this using
blob:
URLs as generated fromURL.createObjectURL()
. See the first comment below.UPDATE 2: I've upgraded Xcode to 13.4, and iOS to 15.5, and still see the problem. Can anyone else reproduce this problem using the app code listed below?
UPDATE: Just updated cordova-plugin-file to the brand new 7.0.0, but the problem still remains.
Images with "file:" URL don't load in app on physical iPhone SE (2022), but load fine on Android and in the iOS simulator. The test case below tries to set
document.body.style.background
, but setting(new Image).src
doesn't work either; the image'sonload()
never runs. After settingdocument.body.style.background
,getComputedStyle(document.body).backgroundImage
shows the correct URL it was set to (as parsed from the background property), but the image never appears.I understand that on a physical iPhone, the various paths are changed every install due to the new ID in the paths, but the test case below accommodates that, so I don't think that's the problem.
Content-Security-Policy
is set to be permissive (see HTML file below), and includesfile:
and others indefault-src
,img-src
, andstyle-src
. (Is there perhaps some system-wide CSP that overrides that?)This is for user-submitted images, so it has to be under
cordova.file.dataDirectory
, not under a read-only directory.Information
I wrote this post on stackoverflow about this problem, but am including all the details here too.
The only plugin I'm using is
cordova-plugin-file
7.0.0 .Command or Code
The test case here was created as a brand new Cordova project.
The
config.xml
of the test case:index.html
is:js/index.js
is:css/index.css
is simply:Finally, I have a background image in
img/home_bg.jpg
that is copied over tocordova.file.dataDirectory
. After this copy, I can read the file correctly fromcordova.file.dataDirectory
.Environment, Platform, Device
I'm developing on a Mac mini (2020) with the M1 chip, running MacOS 12.3 . I'm trying to run the app on a new iPhone SE (2022).
Version information
cordova 11.0.0 cordova-ios 6.2.0 cordova-plugin-file 7.0.0 Mac mini (2020) with M1 chip running MacOS 12.3 iPhone SE (2022) with iOS 15.4 Xcode 13.3
Checklist