Skip to content

ramonvermeulen/react-native-inbeacon

Repository files navigation

MIT license Current npm package version Maintenance Downloads Total downloads Contributors Open issues

react-native-inbeacon

This module is providing a bridge between React Native and the Android / iOS Native SDKs from Inbeacon. This is a third-party module, so it is not developed or maintained by any of the Inbeacon creators themselves. The reason for creating this module was because there was no react-native module for Inbeacon yet, and I had to use it in react-native. So why not publish my code to npm so people can use it and improve it?

Contribution to this module is highly appreciated! 👍

Inbeacon Android SDK: https://github.com/inbeacon/InbeaconSdk-android
Inbeacon iOS SDK: https://github.com/inbeacon/InbeaconSdk-ios

Installation

$ npm install react-native-inbeacon --save

For react-native versions 0.60 and higher the installation will take place through autolinking.

For react-native versions lower than 0.60, please take a look at the manual installation.

For Android the following permission is required in your AndroidManifest.xml:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

Manual installation

Click to expand!

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-inbeacon and add RNInbeacon.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNInbeacon.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java - Add import com.reactlibrary.RNInbeaconPackage; to the imports at the top of the file - Add new RNInbeaconPackage() to the list returned by the getPackages() method
  2. Append the following lines to android/settings.gradle:
    include ':react-native-inbeacon'
    project(':react-native-inbeacon').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-inbeacon/android')
    
  3. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-inbeacon')
    

Documentation

Methods

Please take a look at the Android and iOS SDK documentation for a better understanding.

Name Params Return value iOS Android
initialize clientId: string,
clientSecret: string
Promise<void>
getUserPropertyStringWithFallback property: string,
fallback: string
Promise<string>
getUserPropertyString property: string Promise<string>
putUserPropertyString property: string,
value: string
Promise<void>
getUserPropertyLongWithFallback property: string,
fallback: number
Promise<number>
getUserPropertyLong property: string Promise<number>
putUserPropertyLong property: string,
value: number
Promise<void>
getUserPropertyDoubleWithFallback property: string,
fallback: number
Promise<number>
getUserPropertyDouble property: string Promise<number>
putUserPropertyDouble property: string,
value: number
Promise<void>
hasTag tag: string Promise<boolean>
setTag tag: string Promise<void>
resetTag tag: string Promise<void>
verifyCapabilities None Promise<string>
setLogLevel level: LogLevel Promise<void>
getLogLevel None Promise<string>
setForegroundService state: boolean,
notification: string
Promise<void> No support
askPermission None void
setPpid ppid: string Promise<void>
getPpid None Promise<string>
triggerCustomEvent eventId: number,
eventType: EventType,
extra: string
void

Example

import React from 'react';
import RNInbeacon from 'react-native-inbeacon';
import { useEffect } from 'react-native';

export function RNIBTest({ children }) {

  useEffect(() => {
    RNInbeacon.initialize('CLIENT_ID', 'CLIENT_SECRET').then(() => {
      console.log('RNInbeacon is initialized');
    }).catch(err => {
      console.log('RNInbeacon threw an error while initializing', err);
    });
  }, []);

  return (<>{children}</>)
}

About

React native bridge for the Inbeacon Android and iOS SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published