{"action":"created","issue":{"url":"https://api.github.com/repos/petermetz/cordova-plugin-ibeacon/issues/159","labels_url":"https://api.github.com/repos/petermetz/cordova-plugin-ibeacon/issues/159/labels{/name}","comments_url":"https://api.github.com/repos/petermetz/cordova-plugin-ibeacon/issues/159/comments","events_url":"https://api.github.com/repos/petermetz/cordova-plugin-ibeacon/issues/159/events","html_url":"https://github.com/petermetz/cordova-plugin-ibeacon/issues/159","id":90404994,"number":159,"title":"iOS/Android delegate.didRangeBeaconsInRegion() differences that may result in, \"It's broke!\"","user":{"login":"owntheweb","id":611860,"avatar_url":"https://avatars.githubusercontent.com/u/611860?v=3","gravatar_id":"","url":"https://api.github.com/users/owntheweb","html_url":"https://github.com/owntheweb","followers_url":"https://api.github.com/users/owntheweb/followers","following_url":"https://api.github.com/users/owntheweb/following{/other_user}","gists_url":"https://api.github.com/users/owntheweb/gists{/gist_id}","starred_url":"https://api.github.com/users/owntheweb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owntheweb/subscriptions","organizations_url":"https://api.github.com/users/owntheweb/orgs","repos_url":"https://api.github.com/users/owntheweb/repos","events_url":"https://api.github.com/users/owntheweb/events{/privacy}","received_events_url":"https://api.github.com/users/owntheweb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-23T14:30:46Z","updated_at":"2015-11-29T15:06:00Z","closed_at":null,"body":"Hello,\r\nI made a couple of apps that I've shared, working great on iOS and Android (note: they are crude still, but work!):\r\n\r\niBeacon Ranger:\r\nhttps://github.com/owntheweb/ibeacon-ranger\r\n\r\niBeacon Tour Starter\r\nhttps://github.com/owntheweb/phonegap-ibeacon-tour-starter\r\n\r\nBefore I had a chance to really dig in, I thought that Android was broke somehow after making the iOS version work. However, this plugin was working GREAT on Android (Thank you this plugin ROCKS!). There are however a couple of differences in the way delegate.didRangeBeaconsInRegion() behaves in Android vs. iOS.\r\n\r\n* On Android, sometimes the beacons property is an empty array when delegate.didRangeBeaconsInRegion() is fired. I've worked around this by checking that the property exists and that it is not empty before proceeding further.\r\n\r\n```\r\n...\r\ndelegate.didRangeBeaconsInRegion = function (pluginResult) {\r\n    //Work around Android not picking up iBeacons sometimes when event is fired)\r\n    if(pluginResult.hasOwnProperty('beacons') && pluginResult.beacons.length > 0) {\r\n        //proceed with cross-platform awesomeness\r\n    }\r\n}\r\n...\r\n```\r\n\r\n* Android returns a lowercase UUID while iOS returns an uppercase UUID. This can cause comparison issues when going from one platform to the other. I've worked around this by always forcing lowercase comparisons.\r\n\r\n```\r\n...\r\ndelegate.didRangeBeaconsInRegion = function (pluginResult) {\r\n    var uuid = pluginResult.region.uuid.toLowerCase();\r\n}\r\n...\r\n```\r\n\r\nI recommend making minor adjustments to the Android plugin functionality to be consistent with iOS.\r\n\r\nThanks for this excellent plugin. Let me know if you would like me to attempt a pull request (not very familiar with Java, but I can give it a shot)."},"comment":{"url":"https://api.github.com/repos/petermetz/cordova-plugin-ibeacon/issues/comments/160421466","html_url":"https://github.com/petermetz/cordova-plugin-ibeacon/issues/159#issuecomment-160421466","issue_url":"https://api.github.com/repos/petermetz/cordova-plugin-ibeacon/issues/159","id":160421466,"user":{"login":"fkattan","id":4546,"avatar_url":"https://avatars.githubusercontent.com/u/4546?v=3","gravatar_id":"","url":"https://api.github.com/users/fkattan","html_url":"https://github.com/fkattan","followers_url":"https://api.github.com/users/fkattan/followers","following_url":"https://api.github.com/users/fkattan/following{/other_user}","gists_url":"https://api.github.com/users/fkattan/gists{/gist_id}","starred_url":"https://api.github.com/users/fkattan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fkattan/subscriptions","organizations_url":"https://api.github.com/users/fkattan/orgs","repos_url":"https://api.github.com/users/fkattan/repos","events_url":"https://api.github.com/users/fkattan/events{/privacy}","received_events_url":"https://api.github.com/users/fkattan/received_events","type":"User","site_admin":false},"created_at":"2015-11-29T15:06:00Z","updated_at":"2015-11-29T15:06:00Z","body":"I have seen some differences as well in **didDetermineStateForRegion**. \r\n\r\nIOS reports mayor / minor as integers while android repots as string. I work around this by converting to integer if necessary. \r\n\r\n```javascript\r\nvar major = _.isString(pluginResult.region.major) ? parseInt(pluginResult.region.major) : pluginResult.region.major;\r\nvar minor = _.isString(pluginResult.region.minor) ? parseInt(pluginResult.region.minor) : pluginResult.region.minor;\r\n```"}}