App cache iOS PhoneGap

后端 未结 2 1151
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 05:48

On Android I used

file:///storage/sdcard0/Android/data/my.app.id/cache/

to download (FileTransfer) some images and then show them in my h

2条回答
  •  失恋的感觉
    2020-12-11 06:13

    After days of struggling with this I found the not-so-obvious but very easy solution.

    Instead of using

    file:///var/mobile/Applications//Documents/
    

    to download files on iOS, I used just plain

    cdvfile://localhost/persistent/ 
    

    that I got from

    fileSystem.root.toNativeURL(); // same for Android and iOS
    

    This downloaded my file successfully to

    file:///var/mobile/Applications//Documents/
    

    and this is also the src path I used to display images in HTML.


    Just to clarify what happened in my case: ( when using resolveLocalFileSystemURL() )

    • On Android:

      cdvfile://localhost/persistent/ -> file:///storage/sdcard0/
      

      I had to add

      Android/com.my.appid/cache/
      

      manually and if I removed the app, files got removed as well which is OK.

    • On iOS:

      cdvfile://localhost/persistent/ -> file:///var/mobile/Applications//Documents/
      

      Here I didn't need to add anything, persistent storage was already pointing to my app's own 'cache' which is in this case in Documents folder. This gets removed with the app as well which is correct.

提交回复
热议问题