What you will learn

This tutorial will teach you how to manage:

  • Location permission
  • Bluetooth permission

Pre-requisites - What you need to get started

  • A Gitlab Account: the SDK is available through a private Gitlab. You must have received an email with your user account, including a link to create a password
  • Your SDK user information: in order to initialize the Mobile SDK, you must have received a Login, a Password and a Company name
  • A BLE beacon: a BLE beacon configured on your account is mandatory to test the application
  • An iOS Device: you need a compatible Bluetooth Low Energy iOS device that is able to detect beacons
  • The Xcode application: you must have downloaded Xcode from the App store
  • You must have completed the creating a beacon notification tutorial and the notification strategy introduction tutorial

Step 1: Clone the beacon-tutorial repository

  • Clone the beacon-tutorial repository
git clone https://github.com/Connecthings/sdk-tutorial.git
  • Open the iOs>beacon>11-Permission>Starter folder

Step 2: Configure the SDK

  • Configure your CocoaPod files and .plist

  • Configure your SDK with:

    • the UUID of your beacon
    • the appropriate Adtag Environment
    • your login, password, and company details you received from Connecthings

If you need more information, take a look at the 5 minutes quickstart tutorial.

Step 3: Check the authorization status

  • Open the ViewController.h file.

  • Add the ATBeaconBleLocationStatusDelegate protocole

@interface ViewController : UIViewController<ATBeaconBleLocationStatusDelegate>
  • Open the ViewController.m file.

  • Implement the ATBeacnBLeLOcationStatusDelegate method

-(void)checkBleStatus:(CBCentralManagerState)bleStatus
	   locationStatus:(CLAuthorizationStatus)locationStatus{
}

Note:

  • The CBCentralManagerState returns the Bluetooth status.
  • The CLAuthorizationStatus returns the location permission status.
  • Use the information from the delegate to notify the user about activating bluetooth or authorizing location access.
-(void)checkBleStatus:(CBCentralManagerState)bleStatus
       locationStatus:(CLAuthorizationStatus)locationStatus{

    if(locationStatus==kCLAuthorizationStatusDenied || locationStatus == kCLAuthorizationStatusRestricted){
        _labelStatus.text = NSLocalizedString(@"adtag.warning.Location.status.text", nil);
    }else if (bleStatus== CBCentralManagerStateUnauthorized || bleStatus == CBCentralManagerStatePoweredOff){
        _labelStatus.text = NSLocalizedString(@"adtag.warning.ble.status.text", nil);
    }else if(bleStatus == CBCentralManagerStateUnsupported){
        _labelStatus.text = NSLocalizedString(@"adtag.notsupported.ble.status.text", nil);
    }else{
         _labelStatus.text = NSLocalizedString(@"adtag.ready", nil);
    }

    [_labelStatus setNeedsDisplay];
}
  • Register the delegate on the viewDidAppear method
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[ATBeaconManager sharedInstance] registerAdtagBeaconBleLocationDelegate:self];
}
  • Unregister the delegate in the viewDidDisappear method
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [[ATBeaconManager sharedInstance] registerAdtagBeaconBleLocationDelegate:nil];
}

Step 4: Start testing

  1. In Xcode, click on "Play" to launch the installation process of the application you have just built on your phone

  2. Refuse access to your location

  3. The application displays: "Please authorize the application to access your location".

  4. Deactivate Bluetooth.

  5. The application displays: "Please activate bluetooth".