Urban Airship iOS Integration

Table of Contents

  • Getting started
    • Integrate your project with Urban Airship SDK
    • Integrate your project with Bluedot Point SDK
  • Interaction between Urban Airship SDK and Bluedot Point SDK
    • Start Urban Airship Services
    • Setup Bluedot Location Services
    • Use case

Getting started

Integrate your project with Urban Airship SDK

  1. Add UrbanAirship-iOS-SDK pod to your podfile
    pod "UrbanAirship-iOS-SDK", '~> 10.0'
  2. Add AirshipConfig.plist which includes your App Secret and App Key to your project.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>detectProvisioningMode</key>
        <true/>
        <key>developmentAppKey</key>
        <string>__UrbanAirship development app key__</string>
        <key>developmentAppSecret</key>
        <string>__UrbanAirship development app secret__</string>
        <key>productionAppKey</key>
        <string>__UrbanAirship production app key__</string>
        <key>productionAppSecret</key>
        <string>__UrbanAirship production app secret__</string>
    </dict>
    </plist>
  3. Enable Background Push by including the UIBackgroundModes key with the remote-notification value in your Info.plist and make it is set to Required background modes and remote-notification is set to App downloads content in response to push notifications.
image

You need to upload your Apple Push Notification Service (APNs) Certificate in Urban Airship portal See the APNs Setup documentation for detailed instructions on obtaining your .p12 certificate.

Integrate your project with Bluedot Point SDK

To integrate PointSDK, please refer to the integration steps here

Interaction between Urban Airship SDK and Bluedot Point SDK

Start Urban Airship Services

  1. Import AirshipKit to your class.
    @import AirshipKit;
  2. Take off Urban Airship Services from application:didFinishLaunchingWithOptions: method in your AppDelegate.
    // Call takeOff (which creates the UAirship singleton)
    [UAirship takeOff];
     
    // User notifications will not be enabled until userPushNotificationsEnabled is
    // set YES on UAPush. Once enabled, the setting will be persisted and the user
    // will be prompted to allow notifications. Normally, you should wait for a more
    // appropriate time to enable push to increase the likelihood that the user will
    // accept notifications.
    [UAirship push].userPushNotificationsEnabled = YES;

Setup Bluedot Location Services

  1. Import required header files.
    #import <BDPointSDK.h>
  2. Introducing BDLocationManager which is the entry-point for an app to start using Point SDK.
    [BDLocationManager instance];

    To enable rules which are defined via Bluedot Point Access web interface, it is necessary to call the authentication method from BDLocationManager with your API key.

    /**
    * <p>Authenticate, and start a session with <b>Point Access</b>.
    * This behavior is asynchronous and this method will return immediately. Progress of the authentication process can be
    * monitored by callbacks provided via the <b>sessionDelegate</b> property, or the KVO-enabled <b>authenticationState</b> property.</p>
    *
    * Location Services are required immediately after a successful authentication. If your App has not already called
    * [CLLocationManager auth]
    *
    * <p>It is the responsibility of the Application to respect the authentication life-cycle and ensure that @ref BDLocationManager
    * is not already Authenticated, or in the process of Authenticating, while calling this method.</p>
    *
    * @exception BDPointSessionException Calling this method while in an invalid state will result in a @ref BDPointSessionException being thrown.
    */
    [[BDLocationManager instance] authenticateWithApiKey: apiKey];
    
  3. BDLocationManager expose properties for two delegates with additional features
    • sessionDelegate implements BDPSessionDelegate protocol
      • BDPSessionDelegate protocol provides callbacks informing the application when authentication state changes. The rules defined will only be observed while authenticated.
    • locationDelegate implements BDPLocationDelegate protocol and provide callbacks to notify your application when:
      • Zone information is received. This typically occurs immediately after the authentication process completes.
        didUpdateZoneInfo:
      • Any Custom Action defined is triggered. Either of the following callbacks will be invoked, depending on whether the trigger is a geofence or beacon.
        didCheckIntoFence:inZone:atLocation:willCheckOut:withCustomData:
        didCheckIntoBeacon:inZone:atLocation:withProximity:willCheckOut:withCustomData:
      • Leave the checked-in area. If willCheckOut flag was set, either of the following corresponding callbacks will be made:
        didCheckOutFromFence:inZone:onDate:withDuration:withCustomData:
        didCheckOutFromBeacon:inZone:withProximity:onDate:withDuration:withCustomData:
        
image

Only Custom Actions defined for a Zone will trigger Check-in and Check-out callbacks.

Check-out does not apply to GEOLINE™.

Use case

Objective: Trigger an automated message pushed to end user when the device checks in a geofence or geoline.

Setting automated message: Setup via Urban Airship portal, will be triggered when a new event is posted.

Geofence or Beacon or GEOLINE™: Geographical boundaries , two or more real-world geographical points or BLE Beacons created in Bluedot Point Access Dashboard with Custom Action. (Note: Checkout does not apply to GEOLINE™)

- (void)didCheckIntoFence:(BDFenceInfo *)fence
                   inZone:(BDZoneInfo *)zoneInfo
               atLocation:(BDLocationInfo *)location
             willCheckOut:(BOOL)willCheckOut
           withCustomData:(NSDictionary *)customData
{
    UACustomEvent *customEvent = [UACustomEvent eventWithName:@"bluedot_place_entered"];
    customEvent.interactionType = @"location";
    customEvent.interactionID = zoneInfo.ID;
    
    // Set custom event properties
    [customEvent setStringProperty:zoneInfo.name forKey:@"bluedot_zone_name"];
    for (NSString *key in customData.allKeys) {
        [customEvent setStringProperty:customData[key] forKey:key];
    }
    
    // Record the event in analytics
    [customEvent track];
}

- (void)didCheckOutFromFence: (BDFenceInfo *)fence
                      inZone: (BDZoneInfo *)zoneInfo
                      onDate: (NSDate *)date
                withDuration: (NSUInteger)duration
              withCustomData: (NSDictionary *)customData
{
    UACustomEvent *customEvent = [UACustomEvent eventWithName:@"bluedot_place_exited"];
    customEvent.interactionType = @"location";
    customEvent.interactionID = zoneInfo.ID;
    
    // Set custom event properties
    [customEvent setStringProperty:zoneInfo.name forKey:@"bluedot_zone_name"];
    for (NSString *key in customData.allKeys) {
        [customEvent setStringProperty:customData[key] forKey:key];
    }
    [customEvent setNumberProperty:@(duration) forKey:@"dwell_time"];
    
    // Record the event in analytics
    [customEvent track];
}

- (void)didCheckIntoBeacon: (BDBeaconInfo *)beacon
                    inZone: (BDZoneInfo *)zoneInfo
                atLocation: (BDLocationInfo *)location
             withProximity: (CLProximity)proximity
              willCheckOut: (BOOL)willCheckOut
            withCustomData: (NSDictionary *)customData
{
    UACustomEvent *customEvent = [UACustomEvent eventWithName:@"bluedot_place_entered"];
    customEvent.interactionType = @"location";
    customEvent.interactionID = zoneInfo.ID;
    
    // Set custom event properties
    [customEvent setStringProperty:zoneInfo.name forKey:@"bluedot_zone_name"];
    for (NSString *key in customData.allKeys) {
        [customEvent setStringProperty:customData[key] forKey:key];
    }
    
    // Record the event in analytics
    [customEvent track];
}

- (void)didCheckOutFromBeacon: (BDBeaconInfo *)beacon
                       inZone: (BDZoneInfo *)zoneInfo
                withProximity: (CLProximity)proximity
                       onDate: (NSDate *)date
                 withDuration: (NSUInteger)checkedInDuration
               withCustomData: (NSDictionary *)customData
{
    UACustomEvent *customEvent = [UACustomEvent eventWithName:@"bluedot_place_exited"];
    customEvent.interactionType = @"location";
    customEvent.interactionID = zoneInfo.ID;
    
    // Set custom event properties
    [customEvent setStringProperty:zoneInfo.name forKey:@"bluedot_zone_name"];
    for (NSString *key in customData.allKeys) {
        [customEvent setStringProperty:customData[key] forKey:key];
    }
    [customEvent setNumberProperty:@(duration) forKey:@"dwell_time"];
    
    // Record the event in analytics
    [customEvent track];
}
Created by Bluedot DevOps on February 24, 2018

Start the discussion