At Venue¶
You can setup specific Venues in the platform to monitor, instead of geofences. Using SDK's atVeneue
method, you can detect if a user is inside a Veue when the app is being used. Implement the atVenue
delegate to recieve the response.
[[PulseSDK sharedClient] atVenue];
PulseSDK.sharedClient().atVenue()
At Venue Detection
This is an Enterprise feature. Please contact your account support to enable this on your account.
The atVenue
delegate receives the response with a confidence score which must be used to determine if a user is inside the venue.
- Add the PulseSDKDelegate protocol in your AppDelegate file
@interface AppDelegate : UIResponder< UIApplicationDelegate, PulseSDKDelegate>
class AppDelegate: UIResponder, UIApplicationDelegate, PulseSDKDelegate
- Set the delegate to self in didFinishLaunchingWithOptions method.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[PulseSDK sharedClient].delegate = self;
...
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
PulseSDK.sharedClient().delegate = self
...
}
- Implement the delegate protocol in your AppDelegate file.
- (void)didReceiveVenue:(NSDictionary*)venue error:(NSError*)error userLocation:(CLLocation*)userLocation detectedBeacon:(NSDictionary*)detectedBeacon{
if (userLocation != nil) {
/* user current location available to use */
}
if (error != nil) {
/* possible errors
- Prediction Timeout Error : code 5
- Prediction Error : code 6
- At venue detection is disabled : code 7
if error is At venue detection is disabled so please contact support
*/
NSLog("%d", error.code);
//user info contains the API error response
NSLog("%@", error.userInfo[@"error_message"]);
}
else{
if (venue["location"]){
NSDictionary *dicVenue = venue["location"];
/* name of venue */
NSLog("%@", dicVenue[@"name"]);
}
/*
level of confidence
1 : high
2 : medium
3 : low
*/
NSLog("%d", venue[@"confidence"]);
/* 0 is out of venue
1 is inside venue */
NSLog("%d", venue[@"atVenue"]);
}
if (beacon != nil) {
if (beacon[@"uuid"]){
NSLog(@"%@", beacon[@"uuid"]);
}
if (beacon[@"major"]){
NSLog(@"%@", beacon[@"major"]);
}
if (beacon[@"minor"]){
NSLog(@"%@", beacon[@"minor"]);
}
if (beacon[@"enter_time"]){
/*
when a device enters a beacon
*/
NSLog(@"%@", beacon[@"enter_time"]);
}
if (beacon[@"exit_time"]){
/*
when a device exits a beacon
*/
NSLog(@"%@", beacon[@"exit_time"]);
}
}
}
func didReceiveVenue(_ venue: [AnyHashable : Any]?, error: Error?, userLocation: CLLocation?, detectedBeacon: [AnyHashable : Any]?) {
if let mLocation = userLocation) {
/* user current location available to use */
print("\(mLocation)")
}
if let errorMessage = error {
if let errorResponse = (errorMessage as NSError).userInfo["error_message"] as? String {
/* possible errors
- Prediction Timeout Error : code 5
- Prediction Error : code 6
- At venue detection is disabled : code 7
if error is At venue detection is disabled so please contact support
*/
print("\(errorResponse.code)")
}
}
else{
if let dic = venue{
if let venueDic = dic["location"] as? [String: Any]{
if let name = venueDic["name"] as? String {
/* name of the venue */
print("\(name)")
}
}
if let trace = dic["trace_id"] as? String{
/* trace ID records the call in server */
print("\(trace)")
}
if let confidence = dic["confidence"] as? Int{
/*
1 : high
2 : medium
3 : low
*/
print("\(confidence)")
}
if let inVenue = dic["at_venue"] as? Int{
/* 0 is out of venue
1 is inside venue */
print("\(inVenue)")
}
}
if let beacon = detectedBeacon {
/* these variable are nullable */
let uuid = beacon["uuid"]
let major = beacon["major"]
let minor = beacon["minor"]
let enterTime = beacon["enter_time"]
let exitTime = beacon["exit_time"]
}
}
}
The SDK will invoke this method and will pass venue data if a user is detected within any venue and in case of API or timeout error this method will be invoked with error.
At Venue Detection
The SDK will always pass the current user location if available to this delegate. It is recommended that if you need to use the user's current location in the app, access it from the delegate instead of using CLLocationManager
directly.
At Venue Response¶
When the User is detected inside the venue following location data is available in the response:
"location": {
"id": 90309,
"name": "College Lawn Hotel",
"address": "36 GREVILLE STREET PRAHRAN 3181 VICTORIA",
"latitude": -37.84880317808042,
"longitude": 144.98752832149577,
"reference_id": "1236"
}
Key | Description |
---|---|
id | Refers to the Pulse internal Location ID |
name | Location name which can be set in Pulse platform |
address | Address of the location |
latitude | Latitude of the location |
longitude | Longitude of the location |
reference_id | Reference ID can be set for the location in Pulse platform |