<commit_before># react-native-ibeacon
iBeacon 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.
Beacons don't work in the iOS simulator.

## Installation
Install using npm with `npm install --save react-native-ibeacon`. React Native >=0.4.0 is needed.

You 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`.

NOTE: Make sure you don't have the `RNBeacon` project open separately in XCode otherwise it won't work.

## Usage
```javascript
var React = require('react-native');
var {DeviceEventEmitter} = React;

var Beacons = require('react-native-ibeacon');

// Define a region which can be identifier + uuid, 
// identifier + uuid + major or identifier + uuid + major + minor
// (minor and major properties are numbers)
var region = {
	identifier: 'Estimotes',
	uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'	
};

// Request for authorization while the app is open
Beacons.requestWhenInUseAuthorization();

Beacons.startMonitoringForRegion(region);
Beacons.startRangingBeaconsInRegion(region);

Beacons.startUpdatingLocation();

// Listen for beacon changes
var subscription = DeviceEventEmitter.addListener(
  'beaconsDidRange',
  (data) => {
  	// data.region - The current region
  	// data.region.identifier
  	// data.region.uuid

  	// data.beacons - Array of all beacons inside a region
  	//	in the following structure:
  	//	  .uuid
  	//	  .major - The major version of a beacon
  	//	  .minor - The minor version of a beacon
  	//	  .rssi - Signal strength: RSSI value (between -100 and 0)
  	// 	  .proximity - Proximity value, can either be "unknown", "far", "near" or "immediate"
  	//	  .accuracy - The accuracy of a beacon
  }
);
```

It is recommended to set `NSLocationWhenInUseUsageDescription` in your `Info.plist` file.

## Background mode
For background mode to work, a few things need to be configured:
In the Xcode project, go to Capabilities, switch on "Background Modes" and check both "Location updates" and "Uses Bluetooth LE accessories".


Then, instead of using `requestWhenInUseAuthorization` the method `requestAlwaysAuthorization`.
```javascript
Beacons.requestAlwaysAuthorization();
```

Here, it's also recommended to set `NSLocationAlwaysUsageDescription` in your `Info.plist` file.

Finally 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:
```
  // a region we were scanning for has appeared, ask to open us
  if([launchOptions objectForKey:@"UIApplicationLaunchOptionsLocationKey"])
  {
    //pop a notification to ask user to open, or maybe reload your scanner with delegate so that code fires
  }
```

<commit_msg>Add bgmode image to readme<commit_after># react-native-ibeacon
iBeacon 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.
Beacons don't work in the iOS simulator.

## Installation
Install using npm with `npm install --save react-native-ibeacon`. React Native >=0.4.0 is needed.

You 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`.

NOTE: Make sure you don't have the `RNBeacon` project open separately in XCode otherwise it won't work.

## Usage
```javascript
var React = require('react-native');
var {DeviceEventEmitter} = React;

var Beacons = require('react-native-ibeacon');

// Define a region which can be identifier + uuid, 
// identifier + uuid + major or identifier + uuid + major + minor
// (minor and major properties are numbers)
var region = {
	identifier: 'Estimotes',
	uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'	
};

// Request for authorization while the app is open
Beacons.requestWhenInUseAuthorization();

Beacons.startMonitoringForRegion(region);
Beacons.startRangingBeaconsInRegion(region);

Beacons.startUpdatingLocation();

// Listen for beacon changes
var subscription = DeviceEventEmitter.addListener(
  'beaconsDidRange',
  (data) => {
  	// data.region - The current region
  	// data.region.identifier
  	// data.region.uuid

  	// data.beacons - Array of all beacons inside a region
  	//	in the following structure:
  	//	  .uuid
  	//	  .major - The major version of a beacon
  	//	  .minor - The minor version of a beacon
  	//	  .rssi - Signal strength: RSSI value (between -100 and 0)
  	// 	  .proximity - Proximity value, can either be "unknown", "far", "near" or "immediate"
  	//	  .accuracy - The accuracy of a beacon
  }
);
```

It is recommended to set `NSLocationWhenInUseUsageDescription` in your `Info.plist` file.

## Background mode
For background mode to work, a few things need to be configured:
In the Xcode project, go to Capabilities, switch on "Background Modes" and check both "Location updates" and "Uses Bluetooth LE accessories".

![bgmode](https://raw.githubusercontent.com/frostney/react-native-ibeacon/master/bgmode.gif)

Then, instead of using `requestWhenInUseAuthorization` the method `requestAlwaysAuthorization`.
```javascript
Beacons.requestAlwaysAuthorization();
```

Here, it's also recommended to set `NSLocationAlwaysUsageDescription` in your `Info.plist` file.

Finally 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:
```
  // a region we were scanning for has appeared, ask to open us
  if([launchOptions objectForKey:@"UIApplicationLaunchOptionsLocationKey"])
  {
    //pop a notification to ask user to open, or maybe reload your scanner with delegate so that code fires
  }
```


{'fraction_non_alphanumeric': 0.08946353999357533, 'fraction_numerical': 0.008673305493093478, 'mean_word_length': 4.184845961698585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6086295', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1783, 'n_words': 719}