Cordova file api - localfilesystem undefined


#1

I’m using ionic with cordova (v3.3) file api. Using ion tabs with 2 tabs, 1st tab is default shown when app launch. 1st tab, upon launch, it will invoke cordova file api, I.e using window.requestFileSystem(localfilesystem.PERSISTENT,…,…).

Upon launch, the file api methods and localfilesystem is undefined. But if I swithch to 2nd tab and then go back tab1, then there is no “undefined” error. It seems to me the cordova file plugin doesn’t kick in earlier, but only after I tap on 2nd tab and back to 1st tab.

What could be the reason? How can I resolve it so that when app launch, the 1st tab can access cordova file api?

I didnt use ionicplatform.ready. I also didnt use $q defer/promise for the file api service. Are these relevant to the issue I’m facing?


#2

Hi,

you need to add an eventListener to device ready

    // Wait for device API libraries to load
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, ...);
    }

You need to add the filesystem plugin also => http://cordova.apache.org/docs/en/2.5.0/cordova_file_file.md.html

I hope, it’s can help you,


#3

Thanks you. it’s helpful.