简体   繁体   中英

MobileFirst JSONStore working as intended on emulator, but failing on ios device

I have the following lines of code to add some variables to a local collection:

var data = {
    name: '123',
    brand: '123',
    model: '123',
    img: 'imgurl',
    category: '123',
    segment: 'Recreational',
    pilotFstName: '123',
    pilotLstName: '123',
    insuranceNumber: '123',
    insNumber2: '123',
    extras: '123',
    hasCamera: '123',
    insuranceDate: '123'
};

var collectionName = 'Drones';
var options = {};

WL.JSONStore.get(collectionName)
    .add(data, options)

.then(function(numberOfDocumentsAdded) {
    //handle success
    alert("Done");
})

.fail(function(errorObject) {
    //handle failure
    alert(errorObject);
});

This works fine working in a browser, but fails with an INVALID_SEARCH_FIELD error in any iOS physical device. This is the full error stack in Xcode.

[JSONStoreCollection findWithQueryParts:andOptions:error:] in JSONStoreCollection.m:603 :: Error: JSON_STORE_INVALID_SEARCH_FIELD, code: 22, collection name: Drones, accessor username: jsonstore, currentQuery: (null), JSONStoreQueryOptions: [JSONStoreQueryOptions: sort=( { identifier = desc; } ) filter=(null), limit=1, offset=(null)]

My Collections.js :

function getCollections(){

    return {

        Account : {
            searchFields: {
                userName:"string",
                password:"string",
                frstName:"string",
                lstName:"string",
                mail:"string"
                }
        },  
        Drones : {
            searchFields: {
                name:"string",
                brand:"string",
                model:"string",
                img:"string",
                category:"string",
                segment:"string",
                pilotFstName:"string",
                pilotLstName:"string",
                insuranceNumber:"string",
                insNumber2:"string",
                extras:"string",
                hasCamera:"string",
                insuranceDate:"string"              
                }



        },
        Historial : {
            searchFields: {
                name:"string",
                date:"string",
                posXStart:"string",
                PosYStart:"string",
                PosXFinish:"string",
                PosYFinish:"string"         
            }



        }

    };
};
(function () {

    WL.JSONStore.init(getCollections(), {
        // password : 'PleaseChangeThisPassword'
    })

    .then(function () {
        WL.Logger.debug(['All collections were loaded successfully'].join('\n'));
    })

    .fail(function (errObj) {
        WL.Logger.ctx({pretty: true}).error(errObj);
    });

}()); 

I had to create the collection since you did not mention it in your code snippet.
I also had to first initialize the JSONStore.

The following code works for me both in browser and iOS Simulator (that pretty much means also on a physical device in most cases such as this one):

main.js:

var collectionName = 'myCollectionObject';

var collections = {
    myCollectionObject : {
        searchFields : {
            name: 'string', 
            brand: 'string',
            model: 'string',
            img: 'string',
            category: 'string',
            segment: 'string',
            pilotFstName: 'string',
            pilotLstName: 'string',
            insuranceNumber: 'string',
            insNumber2: 'string',
            extras: 'string',
            hasCamera: 'string',
            insuranceDate: 'string'
        }
    }
};

var data = [{
    name: '123',
    brand: '123',
    model: '123',
    img: 'imgurl',
    category: '123',
    segment: 'Recreational',
    pilotFstName: '123',
    pilotLstName: '123',
    insuranceNumber: '123',
    insNumber2: '123',
    extras: '123',
    hasCamera: '123',
    insuranceDate: '123'
}];

var options = {};
var addOptions = { };

function wlCommonInit(){
    WL.JSONStore.init(collections, options)

    .then(function () {
      return WL.JSONStore.get(collectionName).add(data, addOptions);
    })

    .then(function (numberOfDocumentsAdded) {
      alert ("success: " + numberOfDocumentsAdded);
    })

    .fail(function (errorObject) {
        alert ("failure: " + errorObject);
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM