SPGeofenceManager

@interface SPGeofenceManager : NSObject

Handles registration and event triggering for dynamic geofences. Supports SPGeofenceCircle and SPGeofencePolygon types.

Observe notifications with the name ‘kSPGeofenceEventNotification’ for callbacks. Notifications will include an SPGeofenceEvent object that contains information about a triggered geofence.

  • Declaration

    Objective-C

    + (nonnull instancetype)sharedInstance;

    Swift

    class func sharedInstance() -> Self

    Return Value

    Singleton instance of SPGeofenceManager

  • Unavailable

    call sharedInstance instead

    unavailable method, do not use

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Adds a geofence.

    You can add geofences that will persist for a certain duration by specifying an expiration date with the ‘setExpirationDate’ method in SPGeofence objects.

    Geofences will disappear when the application is restarted.

    Supports SPGeofenceCircle and SPGeofencePolygon types.

    To get geofence trigger events set your location via ‘updateWithLocation:’ method and observe NSNotification with the name ‘kSPGeofenceEventNotification’ to receive events for triggered geofences.

    Alternatively use the SPGeofenceManager ‘hitTest’ methods to check for geofences at locations.

    Declaration

    Objective-C

    - (void)addGeofence:(nonnull SPGeofence *)geofence
                  error:(NSError *_Nullable *_Nullable)error;

    Swift

    func add(_ geofence: SPGeofence, error: NSErrorPointer)

    Parameters

    geofence

    geofence to add

    error

    returned if adding geofence fails

  • Removes a geofence with a specific identifier

    Declaration

    Objective-C

    - (void)removeGeofence:(nonnull NSString *)identifier;

    Swift

    func removeGeofence(_ identifier: String)

    Parameters

    identifier

    unique identifier for geofence

  • Remove multiple geofences with identifiers

    Declaration

    Objective-C

    - (void)removeGeofences:(nonnull NSArray<NSString *> *)identifiers;

    Swift

    func removeGeofences(_ identifiers: [String])

    Parameters

    identifiers

    list of geofence identifiers

  • Fetch a list of currently active geofences asynchronously.

    Declaration

    Objective-C

    - (void)getGeofences:
        (nullable void (^)(NSArray<SPGeofenceInfo *> *_Nonnull))completionBlock;

    Swift

    func getGeofences(_ completionBlock: (([SPGeofenceInfo]) -> Void)? = nil)

    Parameters

    completionBlock

    list of geofences currently active

  • Update location for geofence checks. Observe NSNotification with the name ‘kSPGeofenceEventNotification’ to receive events for triggered geofences.

    Declaration

    Objective-C

    - (void)updateWithLocation:(nonnull SPLocation *)location;

    Swift

    func update(with location: SPLocation)

    Parameters

    location

    coordinate for checking geofences

  • Update a beacon signal strength. This will have an effect only if there’s beacon based geofences at the venues the user is moving through.

    By default you do not need to use this method as the SDK will handle detecting and evaluating beacon geofences internally.

    You simple need to observe NSNotification with the name ‘kSPGeofenceEventNotification’ to receive events for triggered geofences.

    Declaration

    Objective-C

    - (void)updateBeacon:(nonnull NSString *)identifier
                    rssi:(int)rssi
                    date:(nonnull NSDate *)date;

    Swift

    func updateBeacon(_ identifier: String, rssi: Int32, date: Date)

    Parameters

    identifier

    unique to a beacon

    rssi

    received signal strength from the beacon

    date

    when the signal was received

  • Check asynchronously for geofences at a specific location.

    Declaration

    Objective-C

    - (void)hitTest:(nonnull SPLocation *)location
         completion:(nullable void (^)(NSArray<SPGeofenceInfo *> *_Nonnull))
                        completionBlock;

    Swift

    func hitTest(_ location: SPLocation, completion completionBlock: (([SPGeofenceInfo]) -> Void)? = nil)

    Parameters

    location

    coordinate for checking geofences

    completionBlock

    called when hit testing is complete

  • Check asynchronously for geofences at multiple locations.

    Declaration

    Objective-C

    - (void)hitTestLocations:(nonnull NSArray<SPLocation *> *)locations
                  completion:
                      (nullable void (^)(NSArray<SPGeofenceInfo *> *_Nonnull))
                          completionBlock;

    Swift

    func hitTest(_ locations: [SPLocation], completion completionBlock: (([SPGeofenceInfo]) -> Void)? = nil)

    Parameters

    locations

    coordinates for checking geofences

    completionBlock

    called when hit testing is complete

  • Check asynchronously for geofences at coordinates.

    Declaration

    Objective-C

    - (void)hitTestCoordinates:(nonnull NSArray<NSArray<NSNumber *> *> *)coordinates
                    completion:
                        (nullable void (^)(NSArray<SPGeofenceInfo *> *_Nonnull))
                            completionBlock;

    Swift

    func hitTestCoordinates(_ coordinates: [[NSNumber]], completion completionBlock: (([SPGeofenceInfo]) -> Void)? = nil)

    Parameters

    coordinates

    in the following format: : [ [lat, lon, floor], …]

    completionBlock

    called when hit testing is complete