{"action":"created","issue":{"url":"https://api.github.com/repos/transistorsoft/cordova-background-geolocation-lt/issues/8","labels_url":"https://api.github.com/repos/transistorsoft/cordova-background-geolocation-lt/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/transistorsoft/cordova-background-geolocation-lt/issues/8/comments","events_url":"https://api.github.com/repos/transistorsoft/cordova-background-geolocation-lt/issues/8/events","html_url":"https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/8","id":107731984,"number":8,"title":"iOS background geofence","user":{"login":"trivector-se","id":13237303,"avatar_url":"https://avatars.githubusercontent.com/u/13237303?v=3","gravatar_id":"","url":"https://api.github.com/users/trivector-se","html_url":"https://github.com/trivector-se","followers_url":"https://api.github.com/users/trivector-se/followers","following_url":"https://api.github.com/users/trivector-se/following{/other_user}","gists_url":"https://api.github.com/users/trivector-se/gists{/gist_id}","starred_url":"https://api.github.com/users/trivector-se/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trivector-se/subscriptions","organizations_url":"https://api.github.com/users/trivector-se/orgs","repos_url":"https://api.github.com/users/trivector-se/repos","events_url":"https://api.github.com/users/trivector-se/events{/privacy}","received_events_url":"https://api.github.com/users/trivector-se/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-22T14:56:25Z","updated_at":"2015-10-20T15:02:30Z","closed_at":"2015-10-20T15:02:30Z","body":"Hi,\r\n\r\nWe want to use the onGeofence-event to relaunch the app and start gathering data.\r\nAccording to the apple developer documentation\r\nhttps://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/doc/uid/TP40007125-CH3-SW32\r\n\r\nand specifically the quote:\r\n\"The region monitoring service delivers events normally while an app is running in the foreground or background. (You can use this service for both geographic and beacon regions.) For a terminated iOS app, this service relaunches the app to deliver events. Use of this service requires “Always” authorization from the user.\"\r\n\r\nwe take it that the app should relaunch from these events. Although when the app runs in background (home button is pressed or screen is locked - applications has NOT been force-quit) we dont seem to get these events.\r\n\r\n\r\nExample code:\r\n```javascript\r\nbgGeo.onMotionChange(function(isMoving, location, taskId) {\r\n\t\r\n    if (!isMoving) { // if not moving, create a geofence on this location\r\n        bgGeo.addGeofence({\r\n\t\t\tidentifier: \"test\",\r\n\t\t\tradius: 100,\r\n\t\t\tlatitude: location.coords.latitude,\r\n\t\t\tlongitude:location.coords.longitude,\r\n\t\t\tnotifyOnEntry: false,\r\n\t\t\tnotifyOnExit: true\r\n\t\t}, function() {\r\n\t\t\tconsole.log(\"Successfully added geofence\");\r\n\t\t\tPostToServer('ADD_GEOFENCE');// Log on server that we added a geofence\r\n\t\t}, function(error) {\r\n\t\t\tconsole.warn(\"Failed to add geofence \" + error);\r\n\t\t});\r\n    } \r\n    bgGeo.finish(taskId);\r\n})\r\n\r\nbgGeo.onGeofence(function(params, taskId) {\r\n\ttry {\r\n\t\tif ((params.identifier == 'test') && (params.action == 'EXIT')) {\r\n\t\t\tbgGeo.changePace(true); // set aggressive logging if we passed a geofence\r\n\t\t\tPostToServer('EXIT_GEOFENCE');// Log on server that we exited our geofence\r\n\t\t}\r\n\t} catch(e) {\r\n\t\tconsole.error('An error occurred in my application code ' + e);\r\n\t}\r\n\tbgGeo.finish(taskId);\r\n});\r\n```\r\n\r\nWe were thinking that we might be calling \"bgGeo.finish(taskId)\" at the wrong place but we've also tried doing that in the respective callbacks and also \"if (isMoving)\", like so:\r\n\r\n```javascript\r\nbgGeo.onMotionChange(function(isMoving, location, taskId) {\r\n\t\r\n    if (!isMoving) { // if not moving, create a geofence on this location\r\n        bgGeo.addGeofence({\r\n\t\t\tidentifier: \"test\",\r\n\t\t\tradius: 100,\r\n\t\t\tlatitude: location.coords.latitude,\r\n\t\t\tlongitude:location.coords.longitude,\r\n\t\t\tnotifyOnEntry: false,\r\n\t\t\tnotifyOnExit: true\r\n\t\t}, function() {\r\n\t\t\tconsole.log(\"Successfully added geofence\");\r\n\t\t\tPostToServer('ADD_GEOFENCE');// Log on server that we added a geofence\r\n\t\t\tbgGeo.finish(taskId);\r\n\t\t}, function(error) {\r\n\t\t\tconsole.warn(\"Failed to add geofence \" + error);\r\n\t\t\tbgGeo.finish(taskId);\r\n\t\t});\r\n    } else {\r\n\t\tbgGeo.finish(taskId);\r\n\t}\r\n})\r\n```\r\n\r\nWhen consulting our logs on server we can see that we create new geofences, but we never \"EXIT\" them.\r\n\r\nThanks in advance"},"comment":{"url":"https://api.github.com/repos/transistorsoft/cordova-background-geolocation-lt/issues/comments/149594237","html_url":"https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/8#issuecomment-149594237","issue_url":"https://api.github.com/repos/transistorsoft/cordova-background-geolocation-lt/issues/8","id":149594237,"user":{"login":"trivector-se","id":13237303,"avatar_url":"https://avatars.githubusercontent.com/u/13237303?v=3","gravatar_id":"","url":"https://api.github.com/users/trivector-se","html_url":"https://github.com/trivector-se","followers_url":"https://api.github.com/users/trivector-se/followers","following_url":"https://api.github.com/users/trivector-se/following{/other_user}","gists_url":"https://api.github.com/users/trivector-se/gists{/gist_id}","starred_url":"https://api.github.com/users/trivector-se/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trivector-se/subscriptions","organizations_url":"https://api.github.com/users/trivector-se/orgs","repos_url":"https://api.github.com/users/trivector-se/repos","events_url":"https://api.github.com/users/trivector-se/events{/privacy}","received_events_url":"https://api.github.com/users/trivector-se/received_events","type":"User","site_admin":false},"created_at":"2015-10-20T15:02:30Z","updated_at":"2015-10-20T15:02:30Z","body":"After applying your suggested changes, including radius 200 meter, we receive geofence exit. Not always, but often."}}