Inherits from NSObject
Declared in CCHGeofenceService.h
CCHGeofenceService.m

Overview

The Geofence Service is used to create, read, update, and delete geofences on ContextHub.

Structure of geofence NSDictionary

key value
id unique id of the geofence on the ContextHub server
name name of the geofence
latitude latitude of the geofence (must be between -90.0 and 90.0)
longitude longitude of the geofence (must be between -90.0 and 90.0)
radius radius in meters of the geofence
tags NSArray of tags associated with the geofence

Class Methods

regionForGeofence:

Creates a CLCircularRegion from a geofence dictionary.

+ (CLCircularRegion *)regionForGeofence:(NSDictionary *)geofence

Parameters

geofence

NSDictionary that contains geofence information.

Return Value

A CLCircularRegion from a geofence dictionary.

Discussion

Note: This is intended to be used with the geofences that are returned in the CCHGeofenceService.

Declared In

CCHGeofenceService.h

sharedInstance

The singleton instance of the CCHGeofenceService.

+ (instancetype)sharedInstance

Return Value

The singleton instance of the CCHGeofenceService.

Declared In

CCHGeofenceService.h

Instance Methods

createGeofenceWithCenter:radius:name:tags:completionHandler:

Creates a new geofence on the ContextHub server.

- (void)createGeofenceWithCenter:(CLLocationCoordinate2D)center radius:(CLLocationDistance)radius name:(NSString *)name tags:(NSArray *)tags completionHandler:(void ( ^ ) ( NSDictionary *geofence , NSError *error ))completionHandler

Parameters

center

CLLocationCoordinate2D The center coordinate of the geofence.

radius

The radius of to be applied to the geofence.

name

The name of the geofence.

tags

(optional) The tags to be applied to the geofence.

completionHandler

(optional) Called when the request completes. The block is passed an NSDictionary object that represents the geofence. If an error occurs, the NSError will be passed to the block.

Discussion

Note: Tags are used to filter geofences and are used by the CCHSubscriptionService

Declared In

CCHGeofenceService.h

deleteGeofence:completionHandler:

Deletes an existing geofence from ContextHub.

- (void)deleteGeofence:(NSDictionary *)geofence completionHandler:(void ( ^ ) ( NSError *error ))completionHandler

Parameters

geofence

The geofence to be deleted from ContextHub.

completionHandler

Called when the request completes. If an error occurs, the NSError will be passed to the block.

Declared In

CCHGeofenceService.h

getGeofenceWithId:completionHandler:

Gets a geofence from ContextHub using the geofence Id.

- (void)getGeofenceWithId:(NSString *)geofenceId completionHandler:(void ( ^ ) ( NSDictionary *geofence , NSError *error ))completionHandler

Parameters

geofenceId

The id of the geofence stored in ContextHub.

completionHandler

Called when the request completes. The block is passed an NSDictionary object that represents the geofence. If an error occurs, the NSError will be passed to the block.

Declared In

CCHGeofenceService.h

getGeofencesWithTags:location:radius:completionHandler:

Gets geofences from ContextHub server.

- (void)getGeofencesWithTags:(NSArray *)tags location:(CLLocation *)location radius:(CLLocationDistance)radius completionHandler:(void ( ^ ) ( NSArray *geofences , NSError *error ))completionHandler

Parameters

tags

(optional) Tags of the geofences that you are interested in. Passing nil will return geofences without tags.

location

(optional) Location is used to filter the results to the nearest geofences. Passing nil will remove the location filter.

radius

(optional) Radius in meters around the location which ContextHub considers “nearby”. Passing nil to location will cause this parameter to be ignored. Passing 0 will use the default radius of 50 miles (80437 meters)

completionHandler

Called when the request completes. The block is passed an NSArray of NSDictionary objects that represent geofences. If an error occurs, the NSError will be passed to the block.

Declared In

CCHGeofenceService.h

getGeofencesWithTags:operator:location:radius:completionHandler:

Gets geofences from ContextHub server.

- (void)getGeofencesWithTags:(NSArray *)tags operator:(NSString *)tagOperator location:(CLLocation *)location radius:(CLLocationDistance)radius completionHandler:(void ( ^ ) ( NSArray *geofences , NSError *error ))completionHandler

Parameters

tags

(optional) Tags of the geofences that you are interested in. Passing nil will return geofences without tags.

tagOperator

(optional) Operator used to build the query with the tags. Passing ANY will find all geofences that match any of the tags. Passing ALL will find geofences that have all of the tags provided. Passing nil will use the default ALL operator.

location

(optional) Location is used to filter the results to the nearest geofences. Passing nil will remove the location filter.

radius

(optional) Radius in meters around the location which ContextHub considers “nearby”. Passing 0 to radius will cause this parameter to be ignored. Passing 0 will use the default radius of 50 miles (80437 meters)

completionHandler

Called when the request completes. The block is passed an NSArray of NSDictionary objects that represent geofences. If an error occurs, the NSError will be passed to the block.

Declared In

CCHGeofenceService.h

updateGeofence:completionHandler:

Updates a geofence on the ContextHub server.

- (void)updateGeofence:(NSDictionary *)geofence completionHandler:(void ( ^ ) ( NSError *error ))completionHandler

Parameters

geofence

The geofence to be updated on ContextHub.

completionHandler

Called when the request completes. If an error occurs, the NSError will be passed to the block.

Declared In

CCHGeofenceService.h