react-native-inbeacon v0.1.2
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
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-inbeacon
and addRNInbeacon.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNInbeacon.a
to your project'sBuild Phases
➜Link Binary With Libraries
Run your project (
Cmd+R
)<Android
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 thegetPackages()
method
- Add
- 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')
- 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}</>)
}