Fix for iOS with cordova-plugin-file >=8.1.3 #381
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms affected
iOS
Motivation and Context
Since cordova-plugin-file 8.1.3, on iOS, urls returned by
Entry.toURL()
are not anymore in'file://'
format, but inwindow.CDV_ASSETS_URL + '/_app_file_'
format (wherewindow.CDV_ASSETS_URL = scheme + '://' + hostname
, and these values are defined in config.xml)Description
I added a function that returns the
'file://'
url if the url starts withwindow.CDV_ASSETS_URL + '/_app_file_'
. Then I used it to filter thefilePath
andtarget
valuesI'm not sure if it is the best solution, but it works for me.
Testing
We have an app that had no issues with cordova-plugin-file <8.1.3 and cordova-plugin-file-transfer.
After an upgrade to cordova-plugin-file 8.1.3, we noticed file downloads with cordova-plugin-file-transfer was not working.
With this change to cordova-plugin-file-transfer, downloads are working again. As the additional function does nothing if the url does not start with
window.CDV_ASSETS_URL + '/_app_file_'
, it should have no side effectsChecklist
(platform)
if this change only applies to one platform (e.g.(android)
)