Able to read downloaded on-demand resource in iOS Simulator but not on physical device

不羁岁月 提交于 2020-04-27 10:41:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!