Trigger Integration

This is the integration document for the GroundTruth iOS Location Triggers.

The location triggers are used to notify mobile apps, in real-time, whenever their users visit a place or a location. This will help mobile apps to add location-based implementation.

Prerequisites

Integration Steps

Register Trigger
In order to activate trigger callbacks, paste the below line to register for the callbacks.

NotificationCenter.default.addObserver(self, selector: #selector(handleTrigger(_:)), name: NSNotification.Name(rawValue: XADLocationSDK.EVENT_TRIGGER), object: nil)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTrigger:) name: XADLocationSDK.EVENT_TRIGGER object:nil];

Receive Trigger
You will receive trigger callbacks in handleTrigger function.

func handleTrigger(_ notification: Notification) {
    if let info = (notification as NSNotification).userInfo {
        let triggerData = info["data"] as! Array<[String:Any]>
        // Get configured key value of triggers from triggerData
      
        // Example: if event's key value stored as { "proximity":"US" }
        // You can fetch the event value like this
        let value = triggerData ["proximity"] as ? String
      
        // Do the custom implementation here
    }
}
- (void)handleTrigger:(NSNotification *)notification {
    NSDictionary *info = notification.userInfo;
    if ([info objectForKey:@"data"]){
        NSString *triggerData = [userInfo objectForKey:@"data”];
        // Get configured key value of triggers from triggerData
        // Example: if event's key value stored as { "proximity":"US" }
        // You can fetch the event value like this
        NSString *value = [triggerData objectForKey:@"proximity"];
        // Do the custom implementation here
    }
}

Unregister Trigger
In order to de-activate trigger callbacks, paste the below line to unregister the callbacks.

NotificationCenter.default.removeObserver(self)
[[NSNotificationCenter defaultCenter] removeObserver:self];

Full example of Trigger Implementation

import XADLocationSDK

// Register Trigger
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    NotificationCenter.default.addObserver(self, selector: #selector(handleTrigger(_:)), name: NSNotification.Name(rawValue: XADLocationSDK.EVENT_TRIGGER), object: nil)
    }

// Receive Trigger
func handleTrigger(_ notification: Notification) {
    if let info = (notification as NSNotification).userInfo {
        let triggerData = info["data"] as! Array<[String:Any]>
        // Get configured key value of triggers from triggerData
        // Do the custom implementation here
    }
}

// Unregister Trigger
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    NotificationCenter.default.removeObserver(self)
}
#import <XADLocationSDK/XADLocationSDK-Swift.h>

// Register Trigger
- (void)viewWillAppear:(BOOL)animate {
    [super viewWillAppear:animate];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTrigger:) name: XADLocationSDK.EVENT_TRIGGER object:nil];
}

// Receive Trigger
- (void)handleTrigger:(NSNotification *)notification {
    NSDictionary *info = notification.userInfo;
    if ([info objectForKey:@"data"]){
        NSString *triggerData = [userInfo objectForKey:@"data”];
        // Get configured key value of triggers from triggerData
        // Do the custom implementation here
    }
}

// Unregister Trigger
- (void)viewWillDisappear:(BOOL)animate {
    [super viewWillDisappear:animate];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}