iBeacon Sample Project

In this post I want to show you how we can create the simplest iOS app that monitors and ranges devices that follow the iBeacon protocol. An iBeacon device is a BLE (Bluetooth Low Energy) device that transmits its identification information: UUID, major and minor.
You can learn more about iBeacon in this previous post here.

The complete xcode project that is explained in this post can be downloaded from my public github repository here.


Project setup

  1. Create a new empty project in XCode. You can select the Single View Application template.
  2. Enable the permissions needed to use the Core Location services. To do this, add the following two properties in the .plist file of your app:

    NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription.

    Here is an example of these two properties:

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Location is needed to monitor Beacons in range</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Location is needed to monitor Beacons in range</string>
    

My Location Manager

  1. Create the class that will manage all the beacon events: MyLocationManager.
  2. Import the CoreLocation library in the .h file of your new class:
    #import <CoreLocation/CoreLocation.h>
  3. The MyLocationManager class is going to implement the CLLocationManagerDelegate protocol to receive the beacon events:
    @interface MyLocationManager : NSObject <CLLocationManagerDelegate>
  4. The MyLocationManager class also needs two methods so the app can start/stop monitoring iBeacons. Add these methods to the interface:
    
    - (void)startMonitoringUUID:(NSString *)uuid;
    
    - (void)stop;
    
    

Monitoring iBeacons

  1. Open the implementation .m file of our MyLocationManager class and add a private property to keep an instance of the iOS system CLLocationManager class.
    @interface MyLocationManager ()
    @property (strong,nonatomic) CLLocationManager *locationManager;
    @end
    
  2. Implement the start method.
    - (void)startMonitoringUUID:(NSString *)uuid
    {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
    
        // Request permission (mandatory iOS8 + info.plist)
        if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
            [self.locationManager requestAlwaysAuthorization];
    
        CLBeaconRegion *region = [[CLBeaconRegion alloc]
           initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:uuid]
           identifier: uuid];
    
        [self.locationManager startMonitoringForRegion:region];
    }
    

    Line 3. Create an object of the CLLocationManager class.
    Line 4. Set our MyLocationManager object as its delegate.
    Line 7-8. Request permission.
    Line 10-12. Create a region with the UUID received as parameter.
    Line 14. Start monitoring for the recently created region.

  3. Implement the delegate method to receive the iBeacon events. For this small sample app, iBeacon events are just printed to the app log:
    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
    {
        switch (state) {
            case CLRegionStateInside:
                NSLog(@"locationManager didDetermineState INSIDE for %@", region.identifier);
                break;
    
            case CLRegionStateOutside:
                NSLog(@"locationManager didDetermineState OUTSIDE for %@", region.identifier);
                break;
    
            default:
                NSLog(@"locationManager didDetermineState OTHER for %@", region.identifier);
        }
    }
    
  4. Finally implement the stop method:
    - (void)stop
    {
        for(id region in self.locationManager.monitoredRegions) {
            [self.locationManager stopMonitoringForRegion:region];
        }
    }
    

Ranging iBeacons

  1. Add the code to start ranging. A good approach is to start ranging once it has been detected that the user is inside a region. This code is added in the locationManager:didDetermineState:forRegion method:
    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
    {
        switch (state) {
            case CLRegionStateInside:
                NSLog(@"locationManager didDetermineState INSIDE for %@", region.identifier);
                [self.locationManager startRangingBeaconsInRegion:(CLBeaconRegion*)region];
                break;
    
            case CLRegionStateOutside:
                NSLog(@"locationManager didDetermineState OUTSIDE for %@", region.identifier);
                break;
    
            default:
                NSLog(@"locationManager didDetermineState OTHER for %@", region.identifier);
        }
    }
    
  2. Add the code to stop ranging. A good approach is to stop ranging when it is detected that the user is outside a region. This code is added in the locationManager:didDetermineState:forRegion method:
    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
    {
        switch (state) {
            case CLRegionStateInside:
                NSLog(@"locationManager didDetermineState INSIDE for %@", region.identifier);
                [self.locationManager startRangingBeaconsInRegion:(CLBeaconRegion*)region];
                break;
    
            case CLRegionStateOutside:
                NSLog(@"locationManager didDetermineState OUTSIDE for %@", region.identifier);
                [self.locationManager stopRangingBeaconsInRegion:(CLBeaconRegion*)region];
                break;
    
            default:
                NSLog(@"locationManager didDetermineState OTHER for %@", region.identifier);
        }
    }
    
  3. Finally implement the delegate method to receive the iBeacon ranging events. These ranging events are just printed to the app log:
    - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
    {
        if(beacons != nil && (0 < beacons.count)) {
            for(CLBeacon *b in beacons) {
                NSLog(@"%@/%@ %ld", b.major, b.minor, b.proximity);
            }
        }
    }
    

The complete xcode project that has been explained in this post can be downloaded from my public github repository here.

Read More

Introduction to iBeacon

The iBeacon standard is an extension of iOS Location Services. An iBeacon device is a BLE (Bluetooth Low Energy) device that transmits its identification information: UUID, major and minor. This information is hierarchical and the UUID is the beacon’s principal identifier.
The iBeacon functionality provided by iOS allows two types of actions:

  • Region Monitoring. Notifies when the user has entered the specified region.
  • Beacon Ranging. Determines the estimated proximity to the beacons in range: Immediate, Near, Far or Unknown.

A Region in iBeacon terms is a network of iBeacons defined by a shared identifier. A region can be specified by its UUID, major and minor. Major and minor identifiers are optional for a region, but the UUID is necessary.

iOS limits to 20 the number of regions that may be simultaneously monitored by a single app.

For example, if only the UUID is specified for a region, all the iBeacons with that UUID will be considered part of that region.

Beacons inside a UUID region

If we specify the UUID and also a major value for the region, then only the iBeacons with that UUID and major are considered as part of that region.

Beacons inside a UUID+major region

Once a region has been detected, the details of the iBeacons in range inside that region are obtained by ranging, not by monitoring.

Background detection

While the app is running in the foreground it can range to determine the signal strength between the iBeacons and the device. This ranging process is not allowed while the app is not running in the foreground. Only monitoring is allowed while the app is in the background/not running.
Region monitoring is capable of waking the app up from running in the background/not running when the app enters or exits the region. These are the only triggers that will wake the app from running the background/not running: entering or exiting a region. Once the app is awoken it can run for ~10 seconds if closed completely and ~2 minutes if it is running in the background.

Core Location Framework

iBeacon APIs are available in the Core Location Framework. The central point of this framework is the CLLocationManager class. An instance of this class is necessary to start/stop the location services, to configure them, and to receive the related events.
The CLLocationManager reference can be found here.

Read More

Empirical Studies on Usability of mHealth Apps: A Systematic Literature Review

My fourth accepted article has just been published. For my PhD I write scientific articles that are submitted to scientific journals or conferences. This article is in English and it is published in the Journal of Medical Systems. The Journal of Medical Systems is indexed in the Journal Citation Reports (JCR) and its current impact factor is 1.372.

The Journal of Medical Systems provides a forum for the presentation and discussion of the increasingly extensive applications of new information systems techniques and methods across all health care settings. It features four sections focusing on mobile systems, systems level quality improvement, transaction processing systems, and patient facing systems.

Here is the reference and the link to my article:

Zapata BC, Fernández-Alemán JL, Idri A, Toval A. (2015) Empirical Studies on Usability of mHealth Apps: A Systematic Literature Review. J Med Syst 39(2). doi: 10.1007/s10916-014-0182-2

The abstract of the article:

JMS

The release of smartphones and tablets, which offer more advanced communication and computing capabilities, has led to the strong emergence of mHealth on the market. mHealth systems are being used to improve patients’ lives and their health, in addition to facilitating communication between doctors and patients. Researchers are now proposing mHealth applications for many health conditions such as dementia, autism, dysarthria, Parkinson’s disease, and so on. Usability becomes a key factor in the adoption of these applications, which are often used by people who have problems when using mobile devices and who have a limited experience of technology. The aim of this paper is to investigate the empirical usability evaluation processes described in a total of 22 selected studies related to mHealth applications by means of a Systematic Literature Review. Our results show that the empirical evaluation methods employed as regards usability could be improved by the adoption of automated mechanisms. The evaluation processes should also be revised to combine more than one method. This paper will help researchers and developers to create more usable applications. Our study demonstrates the importance of adapting health applications to users’ need.

Read More

Mobile PHRs Compliance with Android and iOS Usability Guidelines

My second accepted article has already been published. For my PhD I write scientific articles that are submitted to scientific journals or conferences. This article is in English and it is published in the Journal of Medical Systems. The Journal of Medical Systems is indexed in the Journal Citation Reports (JCR) and its current impact factor is 1.783.

The Journal of Medical Systems provides a forum for the presentation and discussion of the increasingly extensive applications of new information systems techniques and methods across all health care settings. It features four sections focusing on mobile systems, systems level quality improvement, transaction processing systems, and patient facing systems.

Here is the reference and the link to my article:

Zapata BC, Niñirola AH, Idri A, et al. (2014) Mobile PHRs Compliance with Android and iOS Usability Guidelines. J Med Syst 38:1–16. doi: 10.1007/s10916-014-0081-6

The abstract of the article:

JMS

Mobile Personal Health Records (PHRs) have achieved a particularly strong market share since the appearance of more powerful mobile devices and popular worldwide mobile application markets such as Apple’s App Store and Android’s Google Play. However, Android and Apple have a set of recommendations on design and usability targeted towards developers who wish to publish apps in their stores: Android Design Guidelines and iOS Human Interface Guidelines. This paper aims to evaluate compliance with these guidelines by assessing the usability recommendations of a set of 24 selected mobile PHR applications. An analysis process based on a well-known Systematic Literature Review (SLR) protocol was used. The results show that the 24 mobile PHR applications studied are not suitably structured. 46 % of these applications do not use any of the recommended patterns, using instead lists or springboards, which are deprecated patterns for top-level menus. 70 % of the PHRs require a registration to be able to test the application when these interactions should be delayed. Our study will help both PHR users to select user-friendly mobile PHRs and PHR providers and developers to identify the good usability practices implemented by the applications with the highest scores.

Read More

Seguridad y Privacidad en Carpetas Personales de Salud para Android e iOS

For my PhD I write scientific articles that are submitted to scientific journals or conferences. The objective is to get them accepted and published. Currently we have 3 papers accepted. One of them has recently been published, the only article written in Spanish. The journal is Iberian Journal of Information and Technologies.

The RISTI (Iberian Journal of Information Systems and Technologies) is a peer-reviewed scientific journal, published by Academy Publisher in association with AISTI (Iberian Association of Systems and Information Technology), which focuses the research and the innovative practical application in the field of information systems and technologies. It is a biannual journal that publishes original and innovative articles accepted in an evaluation process by, at least, three members of the Scientific Council.

The journal is published in electronic and print version. The electronic version is free access and here is the reference (APA style) and the link to my article:

Zapata, B., Niñirola, A., Fernández-Alemán, J., & Toval, A. (2014). Seguridad y Privacidad en Carpetas Personales de Salud para Android e iOS. Iberian Journal Of Information Systems And Technologies, 0(13), 35-50. doi:10.4304/risti.13.35-50

RISTI nº 13

The abstract of the article:

Durante los últimos años, el uso de dispositivos móviles como teléfonos inteligentes y tabletas ha suscitado gran interés entre los proveedores de servicios de salud en el mundo de la mSalud. Las Carpetas Personales de Salud (en inglés Personal Health Record o PHR) móviles proporcionan numerosas ventajas y aunque hay estudios que indican que los pacientes están dispuestos a utilizarlos, los índices de uso son aún bajos. La seguridad y la privacidad han sido identificadas como una importante barrera para lograr su amplia adopción. Haciendo uso de un método adaptado de la revisión sistemática de literatura se identificaron 24 PHRs móviles para Android e iOS. La seguridad y privacidad de estos PHRs móviles fueron evaluadas usando un cuestionario de 12 preguntas. Nuestra investigación muestra que los desarrolladores de PHRs móviles han de mejorar sustancialmente sus políticas de privacidad.

 

Read More

Best apps to learn a language

When we want to learn a new language, it is a common thing to search for our own resources. These resources can be books or online sites with lessons, podcasts and exercises. A good alternative is to use mobile applications, even better if you can use a tablet.

Currently I am learning French and I am using mobile applications myself, so I have written a post about the ones I consider the most useful.

1. Duolingo

iPhone Screenshot 2iPhone Screenshot 3

iPhone Screenshot 4

Web page http://www.duolingo.com/
Web version Yes
Devices iPhone/iPad, Android
Languages Spanish, French, Italian, Portuguese, German, English
Price Free
Internet connection Necessary to open a lesson different from your current level

Being totally free, this app provides a variety of exercises that work on all the necessary areas: writing, listening, speaking… It is good for learning vocabulary and grammar, because all the exercises are based on sentences, so both of them are presented together, making it easy to learn.

What I like the most is the translation and listening exercises, in which you have to write whole sentences by translating the original or listening to it. This is more difficult and instructive than just choosing the correct answer from some possible options, like most of apps do.

Your progress is displayed as a nice hierarchy of levels and when it’s been a long time since you last used the app, you will have to do some refresher exercises.

2. MindSnacks

Captura de pantalla del iPhone 1

Captura de pantalla del iPhone 2

Captura de pantalla del iPhone 5

Web page http://www.mindsnacks.com/
Web version No
Devices iPhone/iPad
Languages An app for each language: Spanish, French, Italian, Portuguese, German, Chinese, Japanese.
Price Free but in-app costs to get all the lessons: 4.49€
Internet connection Not necessary

This app is perfect to learn vocabulary. By playing games we can study the vocabulary and have fun with it. To make it more addictive, there are also challenges to get extra points and level up. A disadvantage is not having an app for Android.

What I like the most is that you can play the games using the vocabulary from all the lessons (or just some of them) at the same time, so they are not limited to a specific level, like most of apps do. This functionality is the best way to refresh the vocabulary.

3. Busuu

iPhone Screenshot 3

iPhone Screenshot 4

iPhone Screenshot 2

Web page http://www.busuu.com
Web version Yes
Devices iPhone/iPad, Android
Languages An app for each language: Spanish, French, Italian, Portuguese, German, English, Chinese, Japanese, Russian, Polish, Turkish
Price Free but in-app costs to get all the levels: 4.49€ each level. Full course: 14.99€
Internet connection Necessary to do some types of exercises

This app is the most expensive but it have a lot of different lessons with different types of exercises. In comparation to the other two apps, this app is not so good at making you memorize the vocabulary. The exercises consist on choosing the correct option from the proposed ones. There is not listening exercises and the writing exercises are corrected by the people from the bussu community.

What I like the most is the text comprehension exercise in which a text is displayed, audio included, and we have to answer questions about it. The other advantage of this app is that the language offer is wider.

Read More