Skip to content

Proximity Triggers

Optional

Needed if your app reacts to users entering, leaving or dwelling in areas.

Overview

Oriient Indoor Positioning System (IPS) Proximity Triggers provide tools to add proximity-related events to your mobile application.

The proximity events in the system are managed using IPSProximityTrigger objects. Each IPSProximityTrigger can contain several events (IPSTriggerEvent). When circumstances defined by the event parameters are met the event is triggered and the application using the IPSFramework is notified about this event. Define trigger metadata and then assign that trigger to one or several regions on a map to receive events related to those particular areas.

The event types supported by the system are:

Event Type Triggered when the device
Enter enters one of the specified regions.
Exit exits one of the specified regions.
Dwell enters one of the specified regions and remains there for a defined period.

Info

An overview of the content structure in the system is available here. The regions, triggers, and all their metadata can be configured in the Dashboard, or using the REST API. The metadata defined for a trigger will be available in the IPSProximityTrigger.metadata property. The metadata field opens a wide range of customization options for the proximity service. In our Demo Project, the metadata field is used to show users notifications, show/hide regions, and activate/deactivate triggers.

Observing Proximity Events

To observe the proximity events, use IPSProximity.addProximityEventsObserver() method and implement methods of the IPSProximityEventsObserver protocol. Each of the event types will be reported to the corresponding method of the observer, and will contain the IPSProximityTrigger and the IPSRegion related to the event. The metadata of the region and the trigger might be used to customize how the event is handled.

Important

The proximity events will be triggered only during an active Positioning session, and if current position is locked. See IPSPosition.lockProgress.

Observing Triggers

It is possible to observe all the triggers available on the current active floor. Use the IPSProximity.addTriggersObserver() and implement the methods defined in the IPSTriggersObserver protocol. The framework will notify applications regarding all the added, removed, or updated triggers. When the observer is added, all the triggers currently available will be reported as added.

Local Proximity Events

The triggers described above are configured remotely via the Dashboard or REST API, and are tied to Regions. If you need proximity behavior that's defined entirely on the client — with no Dashboard configuration — use IPSLocalProximityEvent instead.

Each IPSLocalProximityEvent is defined by answering three questions:

IPSLocalProximityEvent(
    groupId: "Product promotions", // used to remove a batch of events at once, see below
    buildingId: "Oriient building id",
    floorOrder: 0,
    trigger: .onEnter(),
    repetitionStrategy: .once(),
    locationDefinition: .closeWalkingDistance(from: coordinate),
    action: {
        // Called when the event triggers
    }
)

Managing Events

Register events using IPSProximity.set(localProximityEvents:) (replaces the current list) or IPSProximity.add(localProximityEvents:) (adds to it). Remove them with IPSProximity.remove(localProximityEvents:) (by reference), IPSProximity.removeAllLocalProximityEvents(), or IPSProximity.removeAllLocalProximityEvents(with:) to remove every event sharing a groupId.

struct ProductPromotion {
    let productLocation: IPSCoordinate
    let productFloor: Int
    let promotionText: String
}

func onProductPromotionsLoaded(_ promotions: [ProductPromotion], in store: IPSBuilding) {
    let events = promotions.map { promotion in
        IPSLocalProximityEvent(
            groupId: nil,
            buildingId: store.id,
            floorOrder: promotion.productFloor,
            trigger: .onEnter(),
            repetitionStrategy: .once(),
            locationDefinition: .closeWalkingDistance(from: promotion.productLocation),
            action: {
                handle(promotion: promotion)
            }
        )
    }

    IPSProximity.set(localProximityEvents: events)
}

func onUserLogout() {
    IPSProximity.removeAllLocalProximityEvents()
}

func handle(promotion: ProductPromotion) {
    // navigate to the promotion screen
}