Skip to content

Geofence

Introduction

StreetHawk's Geofence component is used for running location based campaigns based on user's entry and exit into a geofence area. The document describes integrating StreetHawk SDK's Geofence module into your application. You will be required to register the geofence of interest into StreetHawk console. Steps for registering geofence in StreetHawk console are described below under Create Your First Geofence Based Campaign section.

Pre-requisites

StreetHawkGeofence component depends on StreetHawk's Analytics components. This document assumes that you have already integrated StreetHawkAnalytics component. if not then click here for detailed documentation on StreetHawkAnalytics components which describes steps to integrate Analytics component.

Integration Steps


  • Include StreetHawkGeofence Component

1.In Xamarin Studio, double click on Components folder
2.Click on "Get More Components", and search for StreetHawk Geofence. Click Add to App
3.Once downloaded, click on Add to Project

  • Check StreetHawk.IOS.Geofence.dll reference

Right click project->References->Edit References..., make sure StreetHawk.IOS.Core.dll and StreetHawk.IOS.Geofence.dll are added to project.

For Unified projects, please add corresponding StreetHawk.IOS.Core-Unified.dll and StreetHawk.IOS.Geofence-Unified.dll.

  • Modify Info.plist to enable location service

Add NSLocationAlwaysUsageDescription: request “Always” permission. (Option available in iOS 8). This is needed when you use location functions, including "streethawk/Locations" or "streethawk/Geofences" or "streethawk/Beacons".

  • Include Geofence module

Include StreetHawk component adding following statement:

using StreethawkIOS.Core;
using StreethawkIOS.Geofence;

Must call at least one function of Geofence module to make sure link to it. For very simple use case, just add this line:

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
    //Simply call one function of Geofence module to make sure linking to it.
    SHGeofence.instance().isDefaultLocationServiceEnabled = true;
  • Delay asking for Permission

By default StreetHawk library request location permission when call “streethawkinit” in “didFinishLaunchingWithOptions”. In case you may wish to delay asking the user for location permission, you can add the code be as shown below.

//optional to delay ask for permission
SHGeofence.instance().isDefaultLocationServiceEnabled = false;  //make streethawkinit not trigger location service, delay for later time.

//do SHApp.instance ().streethawkinit (); and other things.

SHGeofence.instance().isLocationServiceEnabled = true;  //later when ready to asking for location service, call this.
  • Get noticed when enter or exit geofence

Add observer to get notified when enter or exit a server monitoring geofence.

SHGeofence.instance ().notifyGeofenceEventCallback = delegate (NSDictionary geofence) 
{
    InvokeOnMainThread ( () => {
        UIAlertView alert = new UIAlertView ("Enter or exit geofence: ", geofence.ToString(), null, "OK", null);
        alert.Show ();
    });
};

Create Your First Geofence Based Campaign


  • Create Geofence in StreetHawk Console

Open StreetHawk console and click on Geofence&Beacons under Growth Campaigns as shown below. Enter Title of the geofence and place the thumb pin at desired location to autofill latitude and longitude of your geofence.

  • Select Geofence filter

Create a new campaign by selecting Campaigns under Growth Campaigns and by clicking the add button. Click on Geofence Filter as shown below. You may opt to select some single geofence or all geofences by clicking on the locations drop down and selecting the geofences for campaigns. You can select the minimum distance for triggering by selecting distance from around drop down menu.

  • Select an action

Proceed to Choose the Engagement Method and select the desired action to be triggered when application user enters the geofence.

  • Set campaign running duration

Schedule your campaign to run over the period of time desired by selecting Real-Time Monitoring option. Please note if the option is not selected, your campaign will fire only once and will target only those users who are present in the geofence at the moment when campaign ran.

  • Save and run campaign

Give a title to your campaign and launch the campaign.