{"id":4575,"url":"https://github.com/frostney/react-native-ibeacon","last_synced_at":"2025-10-05T19:53:16.970Z","repository":{"id":30560651,"uuid":"34115479","full_name":"frostney/react-native-ibeacon","owner":"frostney","description":":satellite: iBeacon support for React Native","archived":false,"fork":false,"pushed_at":"2018-03-19T11:32:41.000Z","size":131,"stargazers_count":375,"open_issues_count":34,"forks_count":54,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-10-29T13:50:08.100Z","etag":null,"topics":["beacon","ibeacon-support","react-native"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frostney.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-17T12:30:28.000Z","updated_at":"2024-08-19T17:00:37.000Z","dependencies_parsed_at":"2022-08-17T19:45:22.362Z","dependency_job_id":null,"html_url":"https://github.com/frostney/react-native-ibeacon","commit_stats":null,"previous_names":["geniuxconsulting/react-native-ibeacon"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Freact-native-ibeacon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Freact-native-ibeacon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Freact-native-ibeacon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Freact-native-ibeacon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frostney","download_url":"https://codeload.github.com/frostney/react-native-ibeacon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beacon","ibeacon-support","react-native"],"created_at":"2024-01-05T20:17:16.715Z","updated_at":"2025-10-05T19:53:11.922Z","avatar_url":"https://github.com/frostney.png","language":"Objective-C","funding_links":[],"categories":["Components","\u003ca name=\"Network:-Native-Modules\"\u003eNetwork: Native Modules\u003c/a\u003e","Objective-C"],"sub_categories":["System"],"readme":"# react-native-ibeacon\niBeacon support for React Native. The API is very similar to the CoreLocation Objective-C one with the only major difference that regions are plain JavaScript objects.\nBeacons don't work in the iOS simulator.\n\nLooking for an Android version? Try out \n- [@mmazzarolo AltBeacon](https://github.com/mmazzarolo/react-native-beacons-android)\n- [@octavioturra's AltBeacon](https://github.com/octavioturra/react-native-alt-beacon)\n\n\n## Support\nThis module supports all iBeacon-compatible devices. Personally, I had the best experience with Estimote beacons, but all devices that support the iBeacon specification should work.\n\n## Installation\nInstall using npm with `npm install --save react-native-ibeacon`. React Native \u003e=0.4.0 is needed.\n\nYou then need to add the Objective C part to your XCode project. Drag `RNBeacon.xcodeproj` from the `node_modules/react-native-ibeacon` folder into your XCode project. Click on the your project in XCode, goto Build Phases then Link Binary With Libraries and add `libRNBeacon.a` and `CoreLocation.framework`.\n\nNOTE: Make sure you don't have the `RNBeacon` project open separately in XCode otherwise it won't work.\n\n## Usage\n```javascript\nvar React = require('react-native');\nvar {DeviceEventEmitter} = React;\n\nvar Beacons = require('react-native-ibeacon');\n\n// Define a region which can be identifier + uuid,\n// identifier + uuid + major or identifier + uuid + major + minor\n// (minor and major properties are numbers)\nvar region = {\n\tidentifier: 'Estimotes',\n\tuuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'\n};\n\n// Request for authorization while the app is open\nBeacons.requestWhenInUseAuthorization();\n\nBeacons.startMonitoringForRegion(region);\nBeacons.startRangingBeaconsInRegion(region);\n\nBeacons.startUpdatingLocation();\n\n// Listen for beacon changes\nvar subscription = DeviceEventEmitter.addListener(\n  'beaconsDidRange',\n  (data) =\u003e {\n  \t// data.region - The current region\n  \t// data.region.identifier\n  \t// data.region.uuid\n\n  \t// data.beacons - Array of all beacons inside a region\n  \t//\tin the following structure:\n  \t//\t  .uuid\n  \t//\t  .major - The major version of a beacon\n  \t//\t  .minor - The minor version of a beacon\n  \t//\t  .rssi - Signal strength: RSSI value (between -100 and 0)\n  \t// \t  .proximity - Proximity value, can either be \"unknown\", \"far\", \"near\" or \"immediate\"\n  \t//\t  .accuracy - The accuracy of a beacon\n  }\n);\n```\n\nIt is recommended to set `NSLocationWhenInUseUsageDescription` in your `Info.plist` file.\n\n## Background mode\nFor background mode to work, a few things need to be configured:\nIn the Xcode project, go to Capabilities, switch on \"Background Modes\" and check both \"Location updates\" and \"Uses Bluetooth LE accessories\".\n\n![bgmode](https://raw.githubusercontent.com/frostney/react-native-ibeacon/master/bgmode.gif)\n\nThen, instead of using `requestWhenInUseAuthorization` the method `requestAlwaysAuthorization`.\n```javascript\nBeacons.requestAlwaysAuthorization();\n```\n\nHere, it's also recommended to set `NSLocationAlwaysUsageDescription` in your `Info.plist` file.\n\nFinally when killed or sleeping and a beacon is found your whole app wont be loaded, just the `didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` delegate so you need to act on it there like:\n```\n  // a region we were scanning for has appeared, ask to open us\n  if([launchOptions objectForKey:@\"UIApplicationLaunchOptionsLocationKey\"])\n  {\n    //pop a notification to ask user to open, or maybe reload your scanner with delegate so that code fires\n  }\n```\n\n\n## Methods\n\nTo access the methods, you need import the `react-native-ibeacon` module. This is done through `var Beacons = require('react-native-ibeacon')`.\n\n### Beacons.requestWhenInUseAuthorization\n```javascript\nBeacons.requestWhenInUseAuthorization();\n```\n\nThis method should be called before anything else is called. It handles to request the use of beacons while the application is open. If the application is in the background, you will not get a signal from beacons. Either this method or `Beacons.requestAlwaysAuthorization` needs to be called to receive data from beacons.\n\n### Beacons.requestAlwaysAuthorization\n```javascript\nBeacons.requestAlwaysAuthorization();\n```\n\nThis method should be called before anything else is called. It handles to request the use of beacons while the application is open or in the background. Either this method or `Beacons.requestWhenInUseAuthorization` needs to be called to receive data from beacons.\n\n### Beacons.getAuthorizationStatus\n```javascript\nBeacons.getAuthorizationStatus(function(authorization) {\n  // authorization is a string which is either \"authorizedAlways\",\n  // \"authorizedWhenInUse\", \"denied\", \"notDetermined\" or \"restricted\"\n});\n```\n\nThis methods gets the current authorization status. While this methods provides a callback, it is not executed asynchronously. The values `authorizedAlways` and `authorizedWhenInUse` correspond to the methods `requestWhenInUseAuthorization` and `requestAlwaysAuthorization` respectively.\n\n### Beacons.startMonitoringForRegion\n```javascript\nvar region = {\n  identifier: 'Estimotes',\n  uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'\n};\n\nBeacons.startMonitoringForRegion(region);\n```\nWhen starting monitoring for beacons, we need to define a region as the parameter. The region is an object, which needs to have at least two values: `identifier` and `uuid`. Additionally, it can also have a `major`, `minor` version or both. Make sure to not re-use the same identifier. In that case, we won't get the data for the beacons. The corresponding events are `regionDidEnter` and `regionDidExit`.\n\n### Beacons.startRangingBeaconsInRegion\n```javascript\nvar region = {\n  identifier: 'Estimotes',\n  uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'\n};\n\nBeacons.startRangingBeaconsInRegion(region);\n```\nWhen ranging for beacons, we need to define a region as the parameter. The region is an object, which needs to have at least two values: `identifier` and `uuid`. Additionally, it can also have a `major`, `minor` version or both. Make sure to not re-use the same identifier. In that case, we won't get the data for the beacons. The corresponding events are `beaconsDidRange`. The event will fire in every interval the beacon sends a signal, which is one second in most cases.\nIf we are monitoring and ranging for beacons, it is best to first call `startMonitoringForRegion` and then call `startRangingBeaconsInRegion`.\n\n### Beacons.startUpdatingLocation\n```javascript\nBeacons.startUpdatingLocation();\n```\n\nThis call is needed for monitoring beacons and gets the initial position of the device.\n\n### Beacons.stopUpdatingLocation\n```javascript\nBeacons.stopUpdatingLocation();\n```\n\nThis method should be called when you don't need to receive location-based information and want to save battery power.\n\n### Beacons.shouldDropEmptyRanges\n```javascript\nBeacons.shouldDropEmptyRanges(true);\n```\nCall this method to stop sending the `beaconsDidRange` event when the beacon list is empty. This can be useful when listening to multiple beacon regions and can reduce cpu usage by 1-1.5%.\n\n## Events\nTo listen to events we need to call `DeviceEventEmitter.addListener` (`var {DeviceEventEmitter} = require('react-native')`) where the first parameter is the event we want to listen to and the second is a callback function that will be called once the event is triggered.\n\n### beaconsDidRange\nThis event will be called for every region in every beacon interval. If you have three regions you get three events every second (which is the default interval beacons send their signal).\nWhen we take a closer look at the parameter of the callback, we get information on both the region and the beacons.\n```javascript\n{\n  region: {\n    identifier: String,\n    uuid: String\n  },\n  beacons: Array\u003cBeacon\u003e\n}\n```\n\nA `Beacon` is an object that follows this structure:\n```javascript\n{\n  uuid: String, // The uuid for the beacon\n  major: Number, // A beacon's major value\n  minor: Number, // A beacon's minor value\n  rssi: Number, // The signal strength, where -100 is the maximum value and 0 the minium.\n                // If the value is 0, this corresponds to not being able to get a precise value\n  proximity: String, // Fuzzy value representation of the signal strength.\n  \t\t     // Can either be \"far\", \"near\", \"immediate\" or \"unknown\"\n  accuracy: Number // One sigma horizontal accuracy in meters, see: http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing/30174335#30174335\n}\n```\nBy default, the array is sorted by the `rssi` value of the beacons.\n\n### regionDidEnter\nIf the device entered a region, `regionDidEnter` is being called.\n\nInside the callback the paramter we can use returns an object with a property `region` that contains the region identifier value as a string. Additionally, we get the UUID of the region through its `uuid` property.\n```javascript\n{\n  region: String,\n  uuid: String\n}\n```\n\n### regionDidExit\nIn the same `regionDidEnter` is called if the device entered a region, `regionDidExit` will be called if the device exited a region and we can't get any signal from any of the beacons inside the region.\n\nAs for the payload, we get a property called `region` that represents the region identifier and is a string as well as the `uuid`.\n```javascript\n{\n  region: String,\n  uuid: String\n}\n```\n\n###authorizationDidChange\nWhen the user permissions change, for example the user allows to always use beacons, this event will be called. The same applies when the user revokes the permission to use beacons.\n```javascript\n// The payload is a string which can either be:\n// \"authorizedAlways\", \"authorizedWhenInUse\", \"denied\", \"notDetermined\" or \"restricted\"\n```\n\n## Troubleshooting\n\n### In the `beaconsDidRange` event, the `beacons` property is just an empty array.\nThere are several things that trigger that behavior, so it's best to follow these steps:\n\n1. Don't use the same identifier for multiple regions\n2. Check if your beacon batteries aren't empty\n3. If monitoring and ranging for beacons, make sure to first monitor and then range\n\n## Style guide\nThis repository uses the Geniux code style guide (based on the AirBnB style guide), for more information see: https://github.com/geniuxconsulting/javascript\n\nFor commit messages, we are following the commit guide from https://github.com/geniuxconsulting/guideline\n\n## License\nMIT, for more information see `LICENSE`\n\n## Changelog\nSee `CHANGELOG.md`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostney%2Freact-native-ibeacon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrostney%2Freact-native-ibeacon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostney%2Freact-native-ibeacon/lists"}