미분류

Building Beacon Apps with Couchbase Mobile

 

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 문서화 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 카우치베이스 싱크 게이트웨이.  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 코우치베이스 모바일 technologies together to deliver location aware apps that work without a network connection.

이 기사 공유하기

작가

윌리엄은 카우치베이스의 모바일 엔지니어링/개발자 경험 팀에서 개발자 옹호자로 활동했습니다. 커피와 코딩에 대한 그의 사랑은 오프라인 대면 경험의 가치를 높이 평가하면서 그를 모바일의 세계로 이끌었습니다. 이전에 윌리엄은 리서치 인 모션(Research In Motion)에서 임베디드 GPS 소프트웨어 엔지니어로 근무했으며, 트위터, 블랙베리, 마이크로소프트의 개발자 relations 팀에서 일했습니다. 윌리엄은 맥길 대학교에서 전기소프트웨어공학을 졸업했습니다.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.