X

The Mobile & Digital Assistant Blog covers the latest in mobile and conversational AI development and engagement

Surviving the mobile offline blues with Oracle Mobile Cloud Service

Chris Muir
Product Manager

Sick of your mobile apps hanging or being totally unusable when they don't have a connection? Tired of waiting for an app to download data and then having to constantly refresh it? Got a mission critical app which would be ideal for mobile but not sure how you're going to deal with update errors when two people attempt to sync the same updated record back to HQ systems?

These are problems that Oracle Mobile Cloud Service (MCS) Data Offline and Synchronization API is designed to solve.

With the February 2016 update to MCS we've revamped the API so the actual programming effort mobile developers need to put into this problem isn't a depressing complex mess of code you have to write yourself, rather it is, well, a doddle. Let's investigate.

Having created a server side custom or storage API, the mobile developer has to do only 3 things: install the MCS mobile client SDK for Android, iOS or Windows, configure the sync policies to state their preferences around fetching data from the device's local cache or remote server side APIs, and then write the client side code using the SDK to initialize the sync engine and fetch the data in just a few lines of code.

The sync policies are the magic of the MCS data offline & sync capabilities.  These options save the mobile developer from a complex programming problem and considering numerous offline use cases & sync edge cases. Rather it is replaced with a list of simple but powerful policy options to choose from, which along with the SDK provided by Oracle takes care of the grunt work of data sync between the mobile client and server.

As example imagine a MCS server side custom API for working with incident reports. In building support into your mobile app to synchronize data with the remote incidents API published via MCS, you make decisions like the following:

  • Fetch the data from the mobile device's local cache if the data is available, but if a cache miss occurs or the data has expired, then fetch the data from the remote MCS custom or storage API instead
  • Expire the local mobile cached data after 300 seconds
  • Periodically refresh any expired locally cached mobile data every 60 seconds to keep the local device's data up to date
  • If the user updates the device's locally cached data and the device is offline, queue those updates to be written to the remote API when the device returns online
  • On writing an update to the remote API service, if the service's copy of the data has already been updated by somebody else before us, define a rule to overwrite the server side change with your mobile client update

The following example demonstrates the choices from above using the sync policy settings of the MCS SDK data offline & sync API in an iOS application:


<key>synchronization</key>

<dict>

 <key>purgeOnStartup</key>

 <true/>

 <key>maxStoreSize</key>

 <integer>100</integer>

 <key>periodicRefreshPolicy</key>

 <string>PERIODIC_REFRESH_POLICY_PERIODICALLY_REFRESH_EXPIRED_ITEMS</string>

 <key>periodicRefreshInterval</key>

 <integer>60</integer>

 <key>policies</key>

  <array>

   <dict>

    <key>path</key>

    <string>/mobile/custom/IncidentsAPI/**</string>

    <key>fetchPolicy</key>

    <string>FETCH_FROM_SERVICE_ON_CACHE_MISS_OR_EXPIRY</string>

    <key>expirationPolicy</key>

    <string>EXPIRE_AFTER</string>

    <key>expireAfter</key>

    <integer>300</integer>

    <key>updatePolicy</key>

    <string>QUEUE_IF_OFFLINE</string>

    <key>confictResolutionPolicy</key>

    <string>CLIENT_WINS</string >

   </dict>

  </array>

 </dict>

</dict>

Having set these options, here's an example in iOS Swift app working with the data offline & sync client side functions to fetch the above policies:


let mcsMbe: OMCMobileBackend =

  OMCMobileBackendManager.sharedManager().defaultMobileBackend

let mcsSync: OMCSynchronization = mcsMbe.synchronization()

mcsSync.initialize()


let mcsEndpoint: OMCMobileEndpoint =

  mcsSync.openEndpoint(OMCMobileObject.self, apiName: "IncidentsAPI",

    endpointPath: "incidents")

let mcsBuilder: OMCFetchObjectCollectionBuilder =

  mcsEndpoint.fetchObjectCollectionBuilder()

mcsBuilder.executeFetchOnSuccess(

  { (objectCollection) -> Void in

    // Do something with objectCollection.getMobileObjects()

  })

  { (error) -> Void in

    // Handle error

  })

It's no more complex than that. No raw REST API calls to MCS to extract the data, no creating timers or threads to periodically refresh expired data with MCS, no dealing with data update collisions and HTTP headers like If-Modified-Since, or when the device goes online and offline which data to use, this is all handled by the SDK, driven by the sync policy options you choose.

Overall writing data offline & sync capabilities as well as fast caching into your mobile apps can be a challenging exercise for day-to-day mobile developers to solve, but are a feature that mobile users are demanding more and more. As we've seen the requirement is massively simplified with Oracle Mobile Cloud Service, leaving your developers more time on building out other compelling features of your mobile app, and not wasting time reinventing the wheel when Oracle has a solution for you which it excels at: managing data.

Image courtesy of stockphotos at FreeDigitalPhotos.net

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.

Recent Content