react-native-nearby-api
Getting started
$ yarn react-native-nearby-api
or $ npm install react-native-nearby-api --save
Mostly automatic installation
$ react-native link react-native-nearby-api
Manual installation
iOS
- To utilize the Nearby SDK,
NearbyMessages
need to be linked to the project. Look to the example for Cocoapods usage.cd ios/ pod init
- Add the following pod to the
Podfile
in the project's target.pod 'NearbyMessage'
- Then
pod install
to install dependencies. - Open the newly generated
.xcworkspace
. - In
node_modules/react-native-nearby-api/ios
, drag and dropRNNearbyApi.xcodeproj
into yourLibraries
group. - In Build Phases > Link Binary with Libraries > Click (+) > Add
libRNNearbyApi.a
. - Build and run project on device.
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.badfeatures.nearby.RNNearbyApiPackage;
to the imports at the top of the file - Add
new RNNearbyApiPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-nearby-api'project(':react-native-nearby-api').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-nearby-api/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-nearby-api')
Usage
See the example app for more detail and code examples.
-
Retrieve your API Keys from the Google Console iOS | Android
-
Add the correct permissions to the AndroidManifest.
<!-- Include if wish to use BLE --><!-- Include if wish to use audio --> -
Add the Android API Key in the AndroidManifest .
-
The iOS API key will be supplied through the
connect()
method. -
Add
NSBluetoothPeripheralUsageDescription
to the Info.plist -
Add
NSMicrophoneUsageDescription
to the iOS project's Info.plist if using audio
; const nearbyAPI = true; // Use BLE only, no audio.nearbyAPI;nearbyAPI;nearbyAPI;nearbyAPI;nearbyAPI;nearbyAPI;nearbyAPI;nearbyAPI;nearbyAPI; // To connect from Google API ClientnearbyAPI; // To check if the nearby API is connected.nearbyAPI; // To disconnect laternearbyAPI; // To publish to nearby devicesnearbyAPI; // To check if the nearby API is publishing.nearbyAPI; // To subscribe to nearby devices broadcastingnearbyAPI; // To check if the nearby API is subscribing.nearbyAPI; // To unpublishnearbyAPI; // To unsubscribenearbyAPI;
Running the Example
-
Install the dependencies in the root folder
yarn
Google Developer Console
Generate an API Key from the- Go to the Google Developers Console.
- Create or select a project to register your application with.
- Click Continue to Enable the API.
- On the Credentials page, create a new API Key. (No key restrictions are needed for this example)
- Copy/Paste your key in example/index.js and in the example AndroidManifest.xml
Android
- To run the example app, the packager must have the
projectRoots
reordered for the example/ directory. In another terminal window:
yarn start --projectRoots <FULL-PATH-TO-REPO>/react-native-nearby-api/example,<FULL-PATH-TO-REPO>/react-native-nearby-api
yarn run:android
adb reverse tcp:8081 tcp:8081
iOS
cd example ios/
bundle exec pod install
- Open
example.xcworkspace
- Add your IP to
AppDelegate.m
jsCodeLocation = ;
-
In another terminal window:
yarn start
-
Run on device
NOTE: If you receive a
duplicate symbols for architecture
error through Xcode, this is a known issue. A work around is to run./renameLogger.sh
afternode_modules
have been installed and you've attempted to run in Xcode.