- iOS 11+
- Swift 4.2+
-
Create an app in the SpotSense Dashboard
-
Download the SpotSense SDK Download the SpotSenseSDK via GitHub or CocoaPods by doing the following
-
Create an XCode Project
-
In Terminal, navigate to the Xcode project directory
-
Create a PodFile by running
pod init
-
Open PodFile in Xcode or a Text Editor
-
Add the following code to your PodFile:
target 'your-app' do # Pods for your-app pod 'SpotSense' end
-
Run
pod install
-
Open your app's
.xcworkspace
file to launch Xcode
-
-
import spotsense
and initialize SpotSense with Client ID and Secret from the Dashboard
import SpotSense
class ViewController: UIViewController, CLLocationManagerDelegate, SpotSenseDelegate {
let spotsense = SpotSense(clientID: "client-id", clientSecret: "client-secret")
}
- Ask to use a user's location and add delegates to handle location updates Note: Apple requires developers to add a description of why they are using a users location to Info.plist
override func viewDidLoad() {
super.viewDidLoad()
// get notification permission, only required if sending notifications with SpotSense
notificationCenter.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
spotsense.notificationStatus(enabled: granted);
}
// get location permissions for spotsense
spotsense.locationManager?.delegate = self
spotsense.locationManager?.activityType = .automotiveNavigation
spotsense.locationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
spotsense.locationManager?.distanceFilter = 5.0
spotsense.locationManager?.requestAlwaysAuthorization()
spotsense.locationManager?.startUpdatingLocation()
spotsense.delegate = self; // attach spotsense delegate to self
if (CLLocationManager.authorizationStatus() == .authorizedAlways || CLLocationManager.authorizationStatus() == .authorizedWhenInUse) {
if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) { // Make sure region monitoring is supported.
}
}
spotsense.delegate = self; // attach spotsense delegate to self
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
//Will Notify Enter event to dashboard for specific region
spotsense.handleRegionState(region: region, state: .inside)
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
//Will Notify Exit event to dashboard for specific region
spotsense.handleRegionState(region: region, state: .outside)
}
func didFindBeacon(beaconScanner: SpotSense, beaconInfo: BeaconInfo, data: NSDictionary) {
//Will Notify Enter event to dashboard for specific beacon
spotsense.handleBeaconEnterState(beaconScanner: beaconScanner, beaconInfo: beaconInfo, data: data)
}
func didLoseBeacon(beaconScanner: SpotSense, beaconInfo: BeaconInfo, data: NSDictionary) {
//Will Notify Exit event to dashboard for specific beacon
spotsense.handleBeaconExitState(beaconScanner: beaconScanner, beaconInfo: beaconInfo, data: data)
}
func ruleDidTrigger(response: NotifyResponse, ruleID: String) {
}
func didUpdateBeacon(beaconScanner: SpotSense, beaconInfo: BeaconInfo, data: NSDictionary) {
}
func didObserveURLBeacon(beaconScanner: SpotSense, URL: NSURL, RSSI: Int) {
}
NSLocationAlwaysAndWhenInUseUsageDescription NSLocationWhenInUseUsageDescription NSBluetoothAlwaysUsageDescription
and explainations to your info.plist e.g $(PRODUCT_NAME) Uses bluetooth to trigger games at certain locations
-
Select your new app and create a geofence or beacon in the SpotSense Dashboard
-
Test your proximity event out in the real world or in the iOS Simulator!
Have a question or got stuck? Let us know in the SpotSense Slack Community or shoot us an email (help@spotsense.io). We are happy to help!