IBeacon Support for React Native

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.

Looking for an Android version? Try out

Support

This 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.

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

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

Then, instead of using requestWhenInUseAuthorization the method requestAlwaysAuthorization.

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
  }

Methods

To access the methods, you need import the react-native-ibeacon module. This is done through var Beacons = require('react-native-ibeacon').

Beacons.requestWhenInUseAuthorization

Beacons.requestWhenInUseAuthorization();

This 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.

Beacons.requestAlwaysAuthorization

Beacons.requestAlwaysAuthorization();

This 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.

Beacons.getAuthorizationStatus

Beacons.getAuthorizationStatus(function(authorization) {
  // authorization is a string which is either "authorizedAlways",
  // "authorizedWhenInUse", "denied", "notDetermined" or "restricted"
});

This 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.

Beacons.startMonitoringForRegion

var region = {
  identifier: 'Estimotes',
  uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
};

Beacons.startMonitoringForRegion(region);

When 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.

Beacons.startRangingBeaconsInRegion

var region = {
  identifier: 'Estimotes',
  uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
};

Beacons.startRangingBeaconsInRegion(region);

When 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. If we are monitoring and ranging for beacons, it is best to first call startMonitoringForRegion and then call startRangingBeaconsInRegion.

Beacons.startUpdatingLocation

Beacons.startUpdatingLocation();

This call is needed for monitoring beacons and gets the initial position of the device.

Beacons.stopUpdatingLocation

Beacons.stopUpdatingLocation();

This method should be called when you don't need to receive location-based information and want to save battery power.

Beacons.shouldDropEmptyRanges

Beacons.shouldDropEmptyRanges(true);

Call 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%.

Events

To 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.

beaconsDidRange

This 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). When we take a closer look at the parameter of the callback, we get information on both the region and the beacons.

{
  region: {
    identifier: String,
    uuid: String
  },
  beacons: Array<Beacon>
}

A Beacon is an object that follows this structure:

{
  uuid: String, // The uuid for the beacon
  major: Number, // A beacon's major value
  minor: Number, // A beacon's minor value
  rssi: Number, // The signal strength, where -100 is the maximum value and 0 the minium.
                // If the value is 0, this corresponds to not being able to get a precise value
  proximity: String, // Fuzzy value representation of the signal strength.
               // Can either be "far", "near", "immediate" or "unknown"
  accuracy: Number // One sigma horizontal accuracy in meters, see: http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing/30174335#30174335
}

By default, the array is sorted by the rssi value of the beacons.

regionDidEnter

If the device entered a region, regionDidEnter is being called.

Inside 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.

{
  region: String,
  uuid: String
}

regionDidExit

In 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.

As for the payload, we get a property called region that represents the region identifier and is a string as well as the uuid.

{
  region: String,
  uuid: String
}

###authorizationDidChange When 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.

// The payload is a string which can either be:
// "authorizedAlways", "authorizedWhenInUse", "denied", "notDetermined" or "restricted"

Troubleshooting

In the beaconsDidRange event, the beacons property is just an empty array.

There are several things that trigger that behavior, so it's best to follow these steps:

  1. Don't use the same identifier for multiple regions
  2. Check if your beacon batteries aren't empty
  3. If monitoring and ranging for beacons, make sure to first monitor and then range

Style guide

This repository uses the Geniux code style guide (based on the AirBnB style guide), for more information see: https://github.com/geniuxconsulting/javascript

For commit messages, we are following the commit guide from https://github.com/geniuxconsulting/guideline

Download Details:
Author: frostney
Source Code: https://github.com/frostney/react-native-ibeacon
License: MIT license

#react  #reactnative  #mobileapp  #javascript 

What is GEEK

Buddha Community

IBeacon Support for React Native
Autumn  Blick

Autumn Blick

1598839687

How native is React Native? | React Native vs Native App Development

If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?

In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.

A brief introduction to React Native

Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.

React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.

Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.

Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.

The popularity of React Native comes from its advantages. Some of its advantages are as follows:

  • Performance: It delivers optimal performance.
  • Cross-platform development: You can develop both Android and iOS apps with it. The reuse of code expedites development and reduces costs.
  • UI design: React Native enables you to design simple and responsive UI for your mobile app.
  • 3rd party plugins: This framework supports 3rd party plugins.
  • Developer community: A vibrant community of developers support React Native.

Why React Native is fundamentally different from earlier hybrid frameworks

Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.

React Native is very close to native. Consider the following aspects as described on the React Native website:

  • Access to many native platforms features: The primitives of React Native render to native platform UI. This means that your React Native app will use many native platform APIs as native apps would do.
  • Near-native user experience: React Native provides several native components, and these are platform agnostic.
  • The ease of accessing native APIs: React Native uses a declarative UI paradigm. This enables React Native to interact easily with native platform APIs since React Native wraps existing native code.

Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.

#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native

Hire Dedicated React Native Developer

Have you ever thought of having your own app that runs smoothly over multiple platforms?

React Native is an open-source cross-platform mobile application framework which is a great option to create mobile apps for both Android and iOS. Hire Dedicated React Native Developer from top React Native development company, HourlyDeveloper.io to design a spectacular React Native application for your business.

Consult with experts:- https://bit.ly/2A8L4vz

#hire dedicated react native developer #react native development company #react native development services #react native development #react native developer #react native

Hire Dedicated React Native Developers - WebClues Infotech

Being one of the emerging frameworks for app development the need to develop react native apps has increased over the years.

Looking for a react native developer?

Worry not! WebClues infotech offers services to Hire React Native Developers for your app development needs. We at WebClues Infotech offer a wide range of Web & Mobile App Development services based o your business or Startup requirement for Android and iOS apps.

WebClues Infotech also has a flexible method of cost calculation for hiring react native developers such as Hourly, Weekly, or Project Basis.

Want to get your app idea into reality with a react native framework?

Get in touch with us.

Hire React Native Developer Now: https://www.webcluesinfotech.com/hire-react-native-app-developer/

For inquiry: https://www.webcluesinfotech.com/contact-us/

Email: sales@webcluesinfotech.com

#hire react native developers #hire dedicated react native developers #hire react native developer #hiring a react native developer #hire freelance react native developers #hire react native developers in 1 hour

Factors affecting the cost of hiring a React Native developer in USA - TopDevelopers.co

Want to develop app using React Native? Here are the tips that will help to reduce the cost of react native app development for you.
Cost is a major factor in helping entrepreneurs take decisions about investing in developing an app and the decision to hire react native app developers in USA can prove to be fruitful in the long run. Using react native for app development ensures a wide range of benefits to your business. Understanding your business and working on the aspects to strengthen business processes through a cost-efficient mobile app will be the key to success.

#best react native development companies from the us #top react native app development companies in usa #cost of hiring a react native developer in usa #top-notch react native developer in usa #best react native developers usa #react native

How much does it cost to develop a React Native mobile app?

React Native allows developers to develop mobile apps that have compatibility with Android, iOS & other operating systems. Due to the features like Native-like functionality and single code reusability and the access of various frameworks in the market, React Native has excelled as the most suitable framework for cross-platform mobile app development.

Why Do Businesses Prefer React Native App Development?

React Native is integrated with JS library that works as the fundamental for developing the app UI. Most businesses choose for developing React Native apps just due to their cross-platform & open-source features. A few further reasons why entrepreneurs & developers choose React Native app development include:

• Lowered Expedition Time

• Simple UI

• Cross-Platform and Code Sharing

• Lesser Workforce and Resources

• Community Assistance

• In-Built Elements and Reusable Codes

• Hot Reload

• JavaScript as Programming Language

• Easy to Execute Updates

Factors That Decide Cost of React Native App Development

If you are an entrepreneur or start-up and looking for cost-effective app development, React Native is one of the ideal options available out there.

• App’s UI/UX Design

• User Authorization

• App Complexity and Functionality

• App Development Team

• App Maintenance

• App Add-ons

• App Distribution

• Location of Development Company

• App Category

React Native cost depends widely on the complexity of a project or the app requirements. The price may also vary based on business requirements. React Native app development per hour can cost from $20 and $30 per hour in India. It can vary as per different locations.

Is React Native a good choice for mobile apps development?

Yes, React Native is the best choice for mobile app development as React apps are faster to develop and it offers better quality than hybrid apps. Additionally, React Native is a mature cross-platform framework.

Best React Native App Development Agency

AppClues Infotech is a leading React Native App Development Company in USA that build robust & innovative mobile app as per your specific business needs. They have a dedicated team of designers and programmers help to make a perfect mobile app.

If you have any mobile app development project in mind get in touch with AppClues Infotech and get the best solution for your business.

#react native app development cost #react native development company #best react native development company in usa #hire react native developers #hire dedicated react native developers & programmers #hire a react native development company