SPGeofenceManager
Objective-C
@interface SPGeofenceManager : NSObject
Swift
class 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() -> SelfReturn 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
geofencegeofence to add
errorreturned 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
identifierunique identifier for geofence
-
Remove multiple geofences with identifiers
Declaration
Objective-C
- (void)removeGeofences:(nonnull NSArray<NSString *> *)identifiers;Swift
func removeGeofences(_ identifiers: [String])Parameters
identifierslist of geofence identifiers
-
Fetch a list of currently active geofences asynchronously.
Declaration
Objective-C
- (void)getGeofences: (nullable void (^)(NSArray<SPGeofenceInfo *> *_Nonnull))completionBlock;Swift
func geofences() async -> [SPGeofenceInfo]Parameters
completionBlocklist 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
locationcoordinate 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
identifierunique to a beacon
rssireceived signal strength from the beacon
datewhen 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) async -> [SPGeofenceInfo]Parameters
locationcoordinate for checking geofences
completionBlockcalled 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]) async -> [SPGeofenceInfo]Parameters
locationscoordinates for checking geofences
completionBlockcalled 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]]) async -> [SPGeofenceInfo]Parameters
coordinatesin the following format: : [ [lat, lon, floor], …]
completionBlockcalled when hit testing is complete
-
Check synchronously for geofences at coordinates.
Declaration
Objective-C
- (nonnull NSArray<SPGeofenceInfo *> *)hitTestCoordinates: (nonnull NSArray<NSArray<NSNumber *> *> *)coordinates;Swift
func hitTestCoordinates(_ coordinates: [[NSNumber]]) -> [SPGeofenceInfo]Parameters
coordinatesin the following format: : [ [lat, lon, floor], …]
SPGeofenceManager Class Reference