The Geofence module 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. Document here describes steps for the same. Steps for registering geofence in StreetHawk console are described below under Create Your First Geofence Based Campaign section.
Add pod to Application's Podfile¶
In pod file of your Application, add one line:
In the OS X command line terminal, enter the following command (making sure that you’re in the directory containing your project and Podfile).
First time to install StreetHawk framework:
Next to check and upgrade to latest StreetHawk framework:
You should see output similar to the following.
Analysing dependencies Downloading dependencies Installing streethawk/Core (1.7.0) Installing streethawk/Geofence (1.7.0) Generating Pods project Integrating client project
This will automatically add StreetHawk/Core and StreetHawk/Geofence open source code into your pod project, and configure everything ready for use.
Note: there is a bug in Cocoapods, which may cause error "No such file or directory". Solution: delete Pods folder and Podfile.lock file, run "pod install" again.
- Modify Info.plist to enable location service
Add NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription: request “Always” permission. This is needed when you use location functions, including "streethawk/Locations" or "streethawk/Geofences" or "streethawk/Beacons".
Delay asking for Permission¶
By default StreetHawk library request location permission when call “registerInstallForApp” in “didFinishLaunchingWithOptions”. In case you may wish to delay asking the user for location permission, you can add the code be as shown below.
//By default location service is enabled when register install. If would like to delay location service, use below code: StreetHawk.isDefaultLocationServiceEnabled = NO; //make registerInstallForApp: not trigger location service, delay for later time. //do [StreetHawk registerInstallForApp...] and other things. StreetHawk.isLocationServiceEnabled = YES; //later when ready to asking for location service, call this.
//By default location service is enabled when register install. If would like to delay location service, use below code: SHApp.sharedInstance().isDefaultLocationServiceEnabled = false //make registerInstallForApp: not trigger location service, delay for later time. //do SHApp.sharedInstance().registerInstallForApp(...) and other things. SHApp.sharedInstance().isLocationServiceEnabled = true; //later when ready to asking for location service, call this.
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.
Check here for API document.