{"_id":"59e70b9fe027ae002e7d2f23","category":{"_id":"59e70b9ee027ae002e7d2ed4","version":"59e70b9ee027ae002e7d2ed2","project":"5496d393f52a630b00519cdd","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-01T11:28:38.565Z","from_sync":false,"order":1,"slug":"getting-started-ios","title":"iOS Reference"},"parentDoc":null,"project":"5496d393f52a630b00519cdd","user":"5496d353f52a630b00519cdc","version":{"_id":"59e70b9ee027ae002e7d2ed2","project":"5496d393f52a630b00519cdd","__v":2,"createdAt":"2017-10-18T08:06:54.462Z","releaseDate":"2017-10-18T08:06:54.462Z","categories":["59e70b9ee027ae002e7d2ed3","59e70b9ee027ae002e7d2ed4","59e70b9ee027ae002e7d2ed5","59e70b9ee027ae002e7d2ed6","59e70b9ee027ae002e7d2ed7","59e70b9ee027ae002e7d2ed8","59e70b9ee027ae002e7d2ed9","59e70b9ee027ae002e7d2eda","59e70b9ee027ae002e7d2edb","59e70b9ee027ae002e7d2edc","59e70b9ee027ae002e7d2edd","59e70b9ee027ae002e7d2ede","59e70b9ee027ae002e7d2edf","5b8661ccdd19310003a3fa0b"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"2.0.10","version":"2.0.10"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-12-01T12:08:38.851Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Activating Geofencing Triggers\"\n}\n[/block]\nAfter activating Placer SDK, set the \"setTriggerNotification\" to \"YES\". This will allow you to receive trigger notifications using the NSNotificationCenter.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Placer setTriggerNotification:YES];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Register your triggers handeling function with NSNotificationCenter\"\n}\n[/block]\nSet your handling function to receive notifications named \"PLNotificationTriggerHit\". \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[NSNotificationCenter defaultCenter] \\n \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\taddObserver:self\\n \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t   selector::::at:::selector(YOUR_GEOFENCE_HIT_HANDLER:)\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t     name:@\\\"PLNotificationTriggerHit\\\"\\n                              object:nil];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n**All done.** Geofence triggers will be sent to your handler function.\nEach NSNotification will contain a NSDictionary of the [Triggered Response Object](doc:triggers).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Example\"\n}\n[/block]\nThe following example shows how to handle a geofence trigger and generate a local push notification:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"    //YOUR GEOFENCE NOTIFICATIONS HANDLER\\n-(void)geofenceHitHandler:(NSNotification *) n {\\n    NSLog(@\\\"Got a notification !\\\");\\n\\n    if (n !=nil )\\n    {\\n        //GET THE LIST OF THE TRIGGERED GEOFENCES\\n        NSMutableArray *geofencesList = [[n userInfo] valueForKeyPath:[NSString stringWithFormat:@\\\"%@\\\", @\\\"rule.geofence_hits\\\"]];\\n\\n        //LOOP THROUGH GEOFENCES\\n        [geofencesList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {\\n            \\n            //LAUNCH LOCAL NOTIFICATION FOR EACH GEOFENCE\\n            UILocalNotification *localNotification = [[UILocalNotification alloc] init];\\n            localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];\\n            localNotification.alertBody = [obj valueForKeyPath:[NSString stringWithFormat:@\\\"%@\\\", @\\\"push_text\\\"]];\\n            localNotification.timeZone = [NSTimeZone defaultTimeZone];\\n            localNotification.soundName = UILocalNotificationDefaultSoundName;\\n            [localNotification setHasAction:YES];\\n            [[UIApplication sharedApplication] \\tscheduleLocalNotification:localNotification];\\n            \\n        }];       \\n    }\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]","excerpt":"Geofencing allows you to receive triggers in the client.\nTo learn more about Geofencing and how you can use it, please go to [Geofencing - Getting Started](doc:getting-started-1).","slug":"geofencing","type":"basic","title":"Geofencing"}

Geofencing

Geofencing allows you to receive triggers in the client. To learn more about Geofencing and how you can use it, please go to [Geofencing - Getting Started](doc:getting-started-1).

[block:api-header] { "type": "basic", "title": "Activating Geofencing Triggers" } [/block] After activating Placer SDK, set the "setTriggerNotification" to "YES". This will allow you to receive trigger notifications using the NSNotificationCenter. [block:code] { "codes": [ { "code": "[Placer setTriggerNotification:YES];", "language": "objectivec" } ] } [/block] [block:api-header] { "type": "basic", "title": "Register your triggers handeling function with NSNotificationCenter" } [/block] Set your handling function to receive notifications named "PLNotificationTriggerHit". [block:code] { "codes": [ { "code": "[[NSNotificationCenter defaultCenter] \n \t\t\t\t\t\t\t\t\t\t\t\taddObserver:self\n \t\t\t\t\t\t\t\t\t\t\t\t selector:@selector(YOUR_GEOFENCE_HIT_HANDLER:)\n\t\t\t\t\t\t\t\t\t\t\t\t\t name:@\"PLNotificationTriggerHit\"\n object:nil];", "language": "objectivec" } ] } [/block] **All done.** Geofence triggers will be sent to your handler function. Each NSNotification will contain a NSDictionary of the [Triggered Response Object](doc:triggers). [block:api-header] { "type": "basic", "title": "Example" } [/block] The following example shows how to handle a geofence trigger and generate a local push notification: [block:code] { "codes": [ { "code": " //YOUR GEOFENCE NOTIFICATIONS HANDLER\n-(void)geofenceHitHandler:(NSNotification *) n {\n NSLog(@\"Got a notification !\");\n\n if (n !=nil )\n {\n //GET THE LIST OF THE TRIGGERED GEOFENCES\n NSMutableArray *geofencesList = [[n userInfo] valueForKeyPath:[NSString stringWithFormat:@\"%@\", @\"rule.geofence_hits\"]];\n\n //LOOP THROUGH GEOFENCES\n [geofencesList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {\n \n //LAUNCH LOCAL NOTIFICATION FOR EACH GEOFENCE\n UILocalNotification *localNotification = [[UILocalNotification alloc] init];\n localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];\n localNotification.alertBody = [obj valueForKeyPath:[NSString stringWithFormat:@\"%@\", @\"push_text\"]];\n localNotification.timeZone = [NSTimeZone defaultTimeZone];\n localNotification.soundName = UILocalNotificationDefaultSoundName;\n [localNotification setHasAction:YES];\n [[UIApplication sharedApplication] \tscheduleLocalNotification:localNotification];\n \n }]; \n }\n}", "language": "objectivec" } ] } [/block]