This library is a wrapper for Google's Nearby Messaging API with notifications already set up. Created using the react-native-create-library
project.
$ yarn add react-native-nearby-messaging-library-with-notifications
or $ npm install -i react-native-nearby-messaging-library-with-notifications
$ yarn add react-native-nearby-messaging-library
or $ npm install react-native-nearby-messaging-library --save
$ react-native link react-native-nearby-messaging-library
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.reactlibrary.RNNearbyMessagingLibraryPackage;
to the imports at the top of the file - Add
new RNNearbyMessagingLibraryPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-nearby-messaging-library' project(':react-native-nearby-messaging-library').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-nearby-messaging-library/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-nearby-messaging-library')
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-nearby-messaging-library
and addRNNearbyMessagingLibrary.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNNearbyMessagingLibrary.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)
- Update permission requests
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
- Add API key
<meta-data
android:name="com.google.android.nearby.messages.API_KEY"
android:value="YOURAPIKEYHERE"
/>
import RNNearbyMessagingLibrary from 'react-native-nearby-messaging-library';
// TODO: What to do with the module?
RNNearbyMessagingLibrary.checkLibraryConnection();
All functions are @ReactMethod
and by default returns void. If you would like for it to return something to the react native layer, feel free to edit the ../android/src/main/java/com/cmendoza/RNNearbyMessagingLibraryModule.java
and use RCTDeviceEventEmitter.
Starts subscribing in the foreground and uses Bluetooth, Location, and Wifi technologies.
Starts subscribing in the background and uses BLE. It is considered best practice to have a notification running if Nearby is listening in the background.
Publishes a message using Google's Nearby Messaging API to all subscribers.
Creates a toast message to confirm that the library was connected properly.
Stops background subscription.
Stops foreground subscription.