In this tutorial, we show you how to use in Radar to show an on-premise mode when a user is in a geofence.
1

Sign up for Radar

If you haven’t already, sign up for Radar to get your API key. You can create up to 1,000 geofences and make up to 100,000 API requests per month for free.Get API keys
2

Create geofences

There are several ways to create geofences:
  1. Create geofence page
  2. CSV import
  3. API
The tag is a group for the geofence. For example, you could set tag = venue for gaming, or tag = restaurant for restaurants. In this tutorial, we’re going to use tag = store.
3

Initialize the SDK

Initialize the SDK with your publishable API key.
import UIKit
import RadarSDK

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    Radar.initialize(publishableKey: "prj_test_pk_...")
    Radar.setUserId("foo")

    return true
  }

}
4

Request foreground permissions

import UIKit
import RadarSDK
import CoreLocation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {

  let locationManager = CLLocationManager()

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    Radar.initialize(publishableKey: "prj_test_pk_...")
    Radar.setUserId("foo")

    self.locationManager.delegate = self
    self.requestLocationPermissions()

    return true
  }

  func requestLocationPermissions() {
    let status = self.locationManager.authorizationStatus

    if status == .notDetermined {
      self.locationManager.requestWhenInUseAuthorization()
    }
  }

}
Learn about platform-specific permissions in the iOS SDK documentation and Android SDK documentation.
5

Change the UI when the user is in a geofence

Call Radar.trackOnce() to track the user’s location in the foreground. In the callback, check user.geofences to determine if the user is in a store, then change the UI to show the on-premise experience.
import UIKit
import RadarSDK
import CoreLocation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {

  let locationManager = CLLocationManager()

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    Radar.initialize(publishableKey: "prj_test_pk_...")
    Radar.setUserId("foo")

    self.locationManager.delegate = self
    self.requestLocationPermissions()

    Radar.trackOnce { (status, location, events, user) in
      let isInStore = user?.geofences?.contains { $0.tag == "store" }
      if isInStore {
        // show on-premise mode
      }
    }

    return true
  }

  func requestLocationPermissions() {
    let status = self.locationManager.authorizationStatus

    if status == .notDetermined {
      self.locationManager.requestWhenInUseAuthorization()
    }
  }

}

Support

Have questions or feedback on this documentation? Let us know! Contact us at radar.com/support.