Sin categoría

Building Beacon Apps with Couchbase Mobile

Lectura de 5 minutos

 

In 2013 Apple Inc. introduced a technology called iBeacon that runs on top of Bluetooth 4.0 protocol which is also known as Bluetooth Low Energy or BLE.  While Bluetooth enabled devices can identify themselves, the process is generally 1 to 1 with a host pairing with a device, such as a smart phone pairing with a Bluetooth headset.  The iBeacon is simply a broadcast service that sends out a few pre-configured pieces of information and can run in parallel with other Bluetooth services.  For discussion, the four parameters of interest when creating beacon applications from solutions like Estimote or from Gimbal are the UUID String, a major 16-bit number, a minor 16-bit number, and a signal strength value.

On iOS7, Apple Inc. provides library functionalities for working with iBeacons and while there are 3rd party libraries for other platforms, the blog here will be focused on iOS.  Combining Couchbase Mobile technologies, Ed Arenberg and the EPage team is developing a service that makes heavy use of iBeacon and utilizes Couchbase Lite for local storage while synchronizing data among numberous devices by using Couchbase Sync Gateway.

Let us now explore the 3 key components of this iBeacon service and how to implement these core features using Couchbase Mobile technologies. Note all of the code is written in Swift 1.2.

Saving data locally on the device to Couchbase Lite

The service will first collect information from nearby beacons and log device informations to the database.  For your exploration, Apple has a good amount of documentación on how to locate and range nearby iBeacons.  For integrating Couchbase Lite into your mobile app, you may look at the Couchbase Mobile developer portal for reference sample code. 

ORM Implementation

We will have the app keep objects in native classes and will implement an ORM to map to and from the Couchbase representation.  When the app locates a group of iBeacons, their class objects will be generated.  The class includes code for saving the object to Couchbase and for loading it from Couchbase.  Here is the class for holding an iBeacon:

 

Syncing Beacon Data

When you are connected to a network, Couchbase Mobile will sync out data using Couchbase Sync Gateway.  This is handled automatically once we set up our push and pull replications, which makes it very easy to keep the system coordinated.  We can add an observer method to listen for the state of the push and pull operations.  However, each device needs to listen for changes in the database for which it needs to take action, so we can add an observer for a database change notification.  When the database changes, we update our local native objects.  To manage the Couchbase interaction, create a Database object that instantiates a singleton.  The main concepts are delineated in the code below:

These are the main pieces that allow the mobile app to run local activities such as monitoring for nearby beacons, saving its local state, and set up sync services to coordinate information consistency amongst app instances.  From this you can build up more functionality and create sophisticated services that can synchronize state across a network of apps. In the next blog we will explore the use of beacon and Couchbase Móvil technologies together to deliver location aware apps that work without a network connection.

Compartir este artículo

Autor

William fue un Defensor de Desarrolladores en el equipo de Ingeniería Móvil/Experiencia de Desarrolladores en Couchbase. Su amor por el café y el código lo ha trascendido al mundo móvil mientras aprecia las experiencias presenciales fuera de línea. Antes, William trabajó en el equipo de Relaciones con Desarrolladores en Twitter, BlackBerry y Microsoft, además de haber sido ingeniero de software de GPS embebido en Research In Motion. William se graduó de la Universidad McGill en Ingeniería de Software Eléctrico

Deja un comentario

¿Listo para comenzar con Couchbase Capella?

Comenzar a construir

Visita nuestro portal para desarrolladores para explorar NoSQL, consultar recursos y comenzar con los tutoriales.

Usa Capella gratis

Empieza a usar Couchbase en tan solo unos clics. Capella DBaaS es la forma más fácil y rápida de comenzar.

Ponte en contacto

¿Quieres saber más sobre las ofertas de Couchbase? Permítenos ayudarte.