Start a new topic
Answered

Collections pull/sync issues

Hi Guys, 


I have an issue pulling data from backend. I can signup, create user, create my Collection, login but pulling from collection (dataStore) doesn't return anything, although it falls through as successful operation. I've tried your starter app Bookshelf and upon adding some books, Sync operation fails. Any hints? You can check my code in snippet 

let dataStore = DataStore<KinveyContact>.collection(.sync)
         dataStore.find() { contacts, error in
            if let fetchedContacts = contacts {
                self.members.append(contentsOf: fetchedContacts)
                print("Succesful fetched KinveyContact(s): \(fetchedContacts)")
                self.tableView.reloadData()
            } else {
                print("Unsuccesful fetched KinveyContact(s) with error: \(String(describing: error))")
            }
        }

Thanks,

Marko


Best Answer
Marko,

I don't see your code for pulling a copy of your data to the device. When using a sync datastore, you should always pull a copy of data to the device first and then work on it offline. You are directly executing 'find()' function without pulling the data. So it will fail as nothing is present locally on your device.

Check following code snippet to pull data from the backend. I have implemented it in my sample app and it is working flawlessly:

 

// Pull data from your backend and save it locally on the device.
dataStore.pull() { (books, error) -> Void in
    if let books = books {
        //succeed
        print("Books: \(books)")
    } else {
        //fail
    }
}

 

 

For better understanding of Kinvey datastore types, please check http://devcenter.kinvey.com/ios/guides/datastore#datastoreTypes.



Thanks,

Pranav

Kinvey

1 Comment

Answer
Marko,

I don't see your code for pulling a copy of your data to the device. When using a sync datastore, you should always pull a copy of data to the device first and then work on it offline. You are directly executing 'find()' function without pulling the data. So it will fail as nothing is present locally on your device.

Check following code snippet to pull data from the backend. I have implemented it in my sample app and it is working flawlessly:

 

// Pull data from your backend and save it locally on the device.
dataStore.pull() { (books, error) -> Void in
    if let books = books {
        //succeed
        print("Books: \(books)")
    } else {
        //fail
    }
}

 

 

For better understanding of Kinvey datastore types, please check http://devcenter.kinvey.com/ios/guides/datastore#datastoreTypes.



Thanks,

Pranav

Kinvey

Login or Signup to post a comment