iOS API Methods

SetSDK.on()

These static functions register a context event handler that will be called when all of the provided contexts are matched. The static function takes a number of parameters, with the only required arguments being a variadic list of Contexts.

Parameters
  • A Context definition.
  • delay - An optional EventDelay, e.g. 5 minutes after departing.
  • withId - An optional String identifier, which will be auto-assigned if absent.
  • eventHandler - A closure that will be called once Context is detected.
public static func on(_: Context...,
                      delay: EventDelay?,
                      withId: String?,
                      eventHandler: @escaping (ContextEvent) -> Void)
Discussion
  • Use the tracked context to drive custom event contexts.

  • If a developer wants to track a particular context, but then delay the firing of the eventHandler, they can specify a EventDelay argument to delay the delivery of the start ContextEvent.

  • Registering with an id that has already been registered will replace the previous registration and event handler.

  • Finally, the required callback closure, which should return a single ContextEvent at a time can be specified using Swift’s trailing closure syntax.

SetSDK.onAny()

The onAny() method is called using the same signature as the on() method. The primary difference is that .on() will match all supplied dimensions of the Context definition, .onAny() will match at least one.

Parameters
  • A Context definition.
  • delay - An optional EventDelay, e.g. 5 minutes after departing.
  • withId - An optional String identifier, which will be auto-assigned if absent) can be used internally to track custom contexts..
  • eventHandler - A closure that will be called once Context is detected.

SetSDK.getLatest()

Having access to the latest context of a user means knowing exactly what context lead to their most recent behavior, and more importantly, how their current context will affect their future actions. The getLatest() API static function provides just this: access to the latest context collection.

public static func getLatest() -> ContextStateCollection?
Returns

An optional ContextStateCollection class object, which contains a property representing just about every Context that the Set SDK manages.

Discussion

This is useful for helping to understand new user sessions, learning why a user is opening the app, what they are trying to solve, and how you can help them faster.

SetSDK.track(event: String)

The Set SDK’s track static function makes it easy to track custom contexts within an app. The developer simply needs to call track with an event name String anywhere within the app’s code base, and Set will take care of the rest.

public static func track(event: String, date: Date = now)
Discussion

To track every time a user clicks an in-app feature and be notified after X number of events, one can use SetSDK.track API to record the events and then leverage the tracked context via the SetSDK.track to setup a subscription. Use of this pattern is also available via the web in Set Dashboard "Recipes" and is a common method of sending timely Notifications.

SDK Setup Methods

SetSDK.launch()

Pretty much what it says on the tin: launch the Set SDK! This is where the magic happens, and is required to use the Set SDK in an app.

public func launch(with configuration: Configuration,
                   completion: @escaping (SetError?) -> Void)
Parameters
  • configuration - A Configuration object.
  • completion - A useful completion closure to be called in the event of a startup error (but that rarely happens!).

User Permissions Helpers

While the Set SDK works out of the box with minimal user permission requirements, things like place-based contexts and behavior states can benefit from additional information. That’s why the Set SDK comes equipped with five endpoints for cleanly and clearly requesting additional permissions from users. The SDK makes these requests in minimally invasive ways, and can even be used to ‘up-grade’ a user’s permission levels well into their app experience. If a given permission is already available (say a previous version of your app has already requested location while in use), then the SDK silently skips the permission request and operates as expected. In short, Set has spent a lot of time thinking about user permissions, so app developers don’t have to!

Read more in iOS Permissions.

SetSDK.requestMotionActivityAccess()

Augments the Set SDK by providing better user behavior states (walking, running, etc) and mobility contexts.

public static func requestMotionActivityAccess()

SetSDK.requestLocationWhileInUse()

Augments the Set SDK by providing better location information while the app is in use. This improves home and work detection rates, and contexts that involve trips or arrivals/departures.

public static func requestLocationWhileInUse()

SetSDK.requestLocationAlways()

Augments the Set SDK to the fullest extent by providing constant location information. This significantly improves home and work detection rates, and contexts that involve trips or arrivals/departures. Always on location also improves the timing of place-based callbacks.

public static func requestLocationAlways()

Other APIs

SetSDK.getDestination()

Given a CLLocation, predicts where the user is most likely to go next if the trip is starting right now. This is useful for any interface where the user is prompted to enter their next destination. When available, labels will be returned with the destination. Based on established, or previously observed, places.

func getDestination(from: CLLocationCoordinate2D, atTime time: Date, minDistance: Double?, maxDistance: Double) -> [TripData]?
Parameters
  • from - a CLLocationCoordinate2D for the starting location.
  • time - a Date for the starting time of the trip
  • minDistance - (Optional) meters to closest possible destination in response (defaults to none or 0)
  • maxDistance - (Optional) meters to most distant possible destination in response (defaults to 50 km)
Returns

An optional array of TripData ordered by their a ranked likelihood of occurrence.



Get in touch

results matching ""

    No results matching ""