Adding support for iBeacons in your iOS App

  1. Copy TQBeaconManager.h to the "Classes" folder. Select "Copy items into destination group's folder (if needed)"
  2. In view controller's .h file of the view in the which you wish to respond to a beacon,
    • import TQBeaconManager.h
    • Add @class TQBeaconManager and
    • Implement MonitorTQProximityDelegate as shown below:


    #import "AdvBar.h"
    #import "TQBeaconManager.h"
    @class AdvBar, TQBeaconManager;
    @interface tQBlogViewController : UIViewController {
     AdvBar *ab;


  3. In viewDidLoad method of view controller's .m file, add below mentioned code snippet. Note: Pass your own App Id (one you have received by registering your app on tapCLIQ)


    TQBeaconManager *beaconManager = [TQBeaconManagersharedTQBeaconManager];
    beaconManager.delegate = self;
    [beaconManager startMonitoringBeaconsForAppId:@"bef99647d04b44ec90c327a5ab599eec"];	


  4. Implement MonitorTQProximityDelegate methods shown below


    -(void)userEnteredRegion: (NSString *)regionIdentifier;
    -(void)userExitedRegion: (NSString *)regionIdentifier;
    -(void)beaconFound:(CLBeacon *)beacon beaconProximity:(NSString *)proximity data:(NSDictionary *)extraData;					


  5. Add code inside respective delegate method in order to respond to user entering / exiting a region OR user's proximity to the beacon.(Code for any change in your app's view OR notification will go in the delegate method)

    You can also invoke an ad view based on beacon proximity by adding below mentioned snippet in
    -(void)beaconFound … method

    Ideally, you should pass uuid, major and minor values of the closest beacon


    // Invoking ad for the beacon
    -(void)beaconFound:(CLBeacon *)beacon beaconProximity:(NSString *)proximity data:(NSDictionary *)extraData {
    CLBeacon *foundBeacon = [beacons firstObject];
    // You can retrieve the beacon data from its properties
    NSString *uuid = foundBeacon.proximityUUID.UUIDString;
    NSString *major = [NSStringstringWithFormat:@"%@", foundBeacon.major];
    NSString *minor = [NSStringstringWithFormat:@"%@", foundBeacon.minor];
    NSDictionary *dict = [[NSDictionaryalloc] initWithObjects:[NSArrayarrayWithObject:uuid,major,minor] forKeys:[NSArrayarrayWithObject:@"uuid",@"major",@"minor"]];
        [[NSNotificationCenterdefaultCenter] postNotificationName:@"CustomTrigger"object:self.calledByuserInfo:dict];


Back to Top