Promise data not returned on device

Hi all, I’ve been pulling my hair out for the last week over this bug so I’m really hoping someone will be able to tell me where I’m going wrong.

I have a ionic app, I’m using PouchDB with the SQLlite cordova plugin. When the app loads if there is any existing data in local storage I’m grabbing it and adding it to PouchDB. This works fine in a desktop browser (Chrome and Safari) and also in the iOS simulator BUT not on a device…

Here’s the code that’s failing:

PouchdbFactory.updateCodes(oldCodesArray).then(function() { // <-- this works, it updates the pouchDB with a reformed array of the old localstorage data

        PouchdbFactory.getAllCodes().then(function(codes) { // Codes is always empty when on the device, but contains all the data in pouchDB when ran in the ios simulator or on desktop chrome/safari
            $ = codes;
            $rootScope.$emit('codesUpdated', codes);
        }).catch(function(error) {
            console.log(error); // I don't get any errors on device

In case you missed the comments in the code, getAllCodes() should return all the data in the the PouchDB (which it does on the ios simulator and on desktop chrome ad safari) however, codes is always empty when ran on device…

At first I thought this was a pouchDB issue but this only happens when deployed on a device (the data is added to PouchDB fune but the returned codes from getAllCodes() is always empty…

Please can someone help and stop me from getting the noose out…

Thanks in advance!