SpotSense 0.1.2

SpotSense 0.1.2

Maintained by Jonny Reiss.


GitHub

Stars0
Watchers1
Forks0
Issues0
Contributors2
Pull Requests0



 
Depends on:
Alamofire>= 0
JWTDecode>= 0
 

SpotSense 0.1.2

SpotSense SDK

Requirements

  • iOS 10+
  • Swift 4.0+

Getting Started

Create an App

  1. Create an app in the SpotSense Dashboard

  2. Download the SpotSense SDK Download the SpotSenseSDK via GitHub or CocoaPods by doing the following

    1. Create an XCode Project

    2. In Terminal, navigate to the Xcode project directory

    3. Create a PodFile by running pod init

    4. Open PodFile in Xcode or a Text Editor

    5. Add the following code to your PodFile:

    target 'your-app' do
        # Pods for your-app
        pod 'SpotSense', '~>0.1'
    end
    
    1. Run pod install

    2. Open your app's .xcworkspace file to launch Xcode

  3. import spotsense and initialize SpotSense with Client ID and Secret from the Dashboard

import UIKit
import CoreLocation
import SpotSense

let spotsense = SpotSense(clientID: "client-id", clientSecret: "client-secret")
class ViewController: UIViewController, CLLocationManagerDelegate, SpotSenseDelegate {...}
  1. 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
let locationManager : CLLocationManager = CLLocationManager()
let notificationCenter = UNUserNotificationCenter.current()

override func viewDidLoad() {
    super.viewDidLoad()

    // get location permissions
    locationManager.requestAlwaysAuthorization()
    locationManager.delegate = self
    spotsense.delegate = self;

    if (CLLocationManager.authorizationStatus() == .authorizedAlways || CLLocationManager.authorizationStatus() == .authorizedWhenInUse) {
        if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) { // Make sure region monitoring is supported.
            spotsense.getRules {}
        }
    }
}

func ruleDidTrigger(response: NotifyResponse, ruleID: String) { // delegate for handling rule triggers
    switch response.getActionType() {
    case "segue":
        if let segueID = response.segueID {
            performSegue(withIdentifier: segueID, sender: nil)
        }
    case "http":
        print("HTTP Response: (String(describing: response.getHTTPResponse()))")
    default:
        print("")
    }
}

func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) { // notify spotsense of geofence changes
    spotsense.handleRegionState(region: region, state: state)
}
  1. Select your new app and create a rule in the SpotSense Dashboard
  2. Test your rule 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 ([email protected]). We are happy to help!