Track local changes, pull from custom api, pull from ids RRS feed

  • Question

  • I am transitioning my iOS app to Azure Mobile Apps with offline sync, and I have some questions:

    1. I was using events to inform changes of the local SqlLite database, and the UI/screens subscribed to stay updated. Now, using Offline Sync, when I do Pull I don't know what objects were changed, added or removed. Is there a way to track changes from the local database?

    2. In my app some UIs/screens need to pull data quickly from the backend, querying from 5 different tables and with joins. I found that to do this in Offline Sync I have to make consecutive 5 pulls (am I right?), when I could do this in one quick request. Is there a way to make a Custom API that retrieves all these objects in one call and then add it manually to the local SqlLite database without corrupting future syncs or existing objects?

    3. How can I pull many (more than one) objects having their Ids using offline sync?

    Thanks! :)
    Thursday, June 30, 2016 11:31 PM


All replies

  • I'm assuming you're using the native iOS SDK for Mobile Apps. 
    1. You should be able to attach a context to your Core Data model to get notified of changes, since the changes will always be writte nto that store.
    2. That's right, you need do 5 pull operations. You could do a Custom API to do this, but then you have to manage incremental sync yourself. It is doable, however. Future syncs don't depend on the Pull operation, but just the version column if you're using conflict handlign.
    3. You can pull multiple objects by ID by adding a predicate to PullWithQuery. However, you should be careful about constraining with too many IDs, since the filter will be sent as a query string and there is a maximum query string length. 

    Friday, July 1, 2016 12:58 AM
  • Thanks for your fast response Donna.

    1. Sorry, I should have clarified, I'm using Xamarin.iOS. I was using Sqlite.Net before and I handled every CUD myself raising events to inform what changes were done in the local database.

    2. Let's say I retrieve 10 objects from my custom api, and I add them with InsertAsync() to the local database. How bad is this? It means it will retrieve again that objects in the next pull? or it will fail completely if, let's say, that object already existed in the local database? Because if it only retrieves the objects again in the next pull, I would sacrifice that for speed. It would mean fast UI/screen load and happy users :)

    3. Answered.

    • Edited by Chris7386 Friday, July 1, 2016 1:46 AM
    Friday, July 1, 2016 1:46 AM
    1. On Xamarin, you can use the EventManager interface to get notified of local updates that happen as part of the pull:

    await client.SyncContext.InitializeAsync(store, StoreTrackingOptions.NotifyLocalAndServerOperations);
    var subscription = client.EventManager.Subscribe<StoreOperationCompletedEvent>(OnStoreOperationCompleted);

    2. If you insert the objects with syncTable.InsertAsync, then you will also be adding a tracking operation and the SDK will try to send an insert to the server when you do PushAsync. Instead, you should go to the local store layer directly and use UpsertAsync However, you need to add locking to make sure that the SDK is not concurrently doing any database writes as part of a pull or push operation.

    On the next pull, you'll get the same object again, but nothing should break.

    Friday, July 1, 2016 2:26 AM
  • Perfect answer. Thanks!
    Friday, July 1, 2016 2:32 AM
  • I just saw here the use of [ExpandProperty("Equipments")] that returns a query with .Include() (like join), I guess it implements expandable of OData. Could this solution be used in offline sync? Can I call .pull() from the client and automatically cache the parent and children objects in the local sqlite database in one call?


    Monday, July 4, 2016 9:03 PM