问题
I am using Apple On-Demand resources to try to load a game inside my App.
The ODR retrieval works well (with a custom plugin that I developed) but then I am able to read the downloaded on-demand resource only on the simulator, I cannot do the same on a physical device!
The path of the downloaded file that I get through the Objective-C code of my custom plugin
( NSString *path= [[NSBundle mainBundle] pathForResource:@"flying-block-game" ofType:@"html" ];
)
..is the following:
- Simulator
[odr] Path for flying-block-game.html: '/Users/myUser/Library/Developer/CoreSimulator/Devices/D016D3BC-E9F9-43F2-8EC1-9A471819A9B5/data/Library/OnDemandResources/AssetPacks/89A6F4A7-D148-419B-B5BB-FF23950612E2/15538308173473852725/com.us-company.sports-beta-enterprise.asset-pack-5a105e8b9d40e1329780d62ea2265d8a.assetpack/flying-block-game.html'
- Physical device:
[odr] Path for flying-block-game.html: '/var/mobile/Library/OnDemandResources/AssetPacks/2F2887A0-7A16-4E5D-81C2-1C688A69DA80/15538308173473852725/com.us-company.sports-beta-enterprise.asset-pack-5a105e8b9d40e1329780d62ea2265d8a.assetpack/flying-block-game.html'
The error I get when I try to read the file (using cordova-plugin-file) is 5 - ENCODING_ERR
but I doubt it's accurate as I also got the same trying to fetch files from a non-existing path.
This is the JS code I use to try to read the downloaded on-demand asset using the path returned by my custom plugin:
// On-Demand Resources POC
window.plugins.fetchOdr({ // my custom plugin
tagName: 'my-test-tag',
success: (path) => {
alert(`Success! Odr path: ${path}`);
// This Breaks.. v V V vvvvvvvVVVVVVvvvvvVVVVvv o . <<------------------------=
window.resolveLocalFileSystemURL(
`file://${path}`,
(data) => {
const fileEntry = data;
fileEntry.file(
(file) => {
const reader = new FileReader();
reader.onloadend = function(data) {
console.log(`[odr] Successful file read: ${this.result}`, data);
// do stuff here.. (display in webview)
};
reader.readAsText(file);
},
(err) => alert(`[odr] > File read Error: ${JSON.stringify(err)}`),
);
},
(err) => alert(`[odr] > FileEntry generation Error: ${JSON.stringify(err)}`),
);
},
What am I doing wrong? How can I properly read the file on the physical device too?
I even added these preferences to my config.xml file but it didn't help:
<preference id="TEMPORARY-FULL-WHITELIST" name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference id="ODR-POC" name="iosPersistentFileLocation" value="Library" />
来源:https://stackoverflow.com/questions/61094404/able-to-read-downloaded-on-demand-resource-in-ios-simulator-but-not-on-physical