Giter VIP home page Giter VIP logo

react-native-nearby-api's Introduction

react-native-nearby-api npm version

Getting started

$ yarn add 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 'NearbyMessages'
    
  • Then pod install to install dependencies.
  • Open the newly generated .xcworkspace.
  • In node_modules/react-native-nearby-api/ios, drag and drop RNNearbyApi.xcodeproj into your Libraries group.
  • In Build Phases > Link Binary with Libraries > Click (+) > Add libRNNearbyApi.a.
  • Build and run project on device.

Android

  1. 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 the getPackages() method
  1. 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')
  2. 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 -->
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <!-- Include if wish to use audio -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
  • Add the Android API Key in the AndroidManifest .

    <meta-data
      android:name="com.google.android.nearby.messages.API_KEY"
      android:value="MY_API_KEY" />
  • 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

import NearbyApi from "react-native-nearby-api";

const nearbyAPI = new NearbyAPI(true); // Use BLE only, no audio.
nearbyAPI.onConnected(message => {
  console.log(message);
});
nearbyAPI.onDisconnected(message => {
  console.log(message);
});
nearbyAPI.onFound(message => {
  console.log("Message Found!");
  console.log(message);
});
nearbyAPI.onLost(message => {
  console.log("Message Lost!");
  console.log(message);
});
// Android Only
nearbyAPI.onDistanceChanged((message, value) => {
  console.log("Distance Changed!");
  console.log(message, value);
});
// Android Only
nearbyAPI.onBLESignalChanged((message, value) => {
  console.log("BLE Signal Changed!");
  console.log(message, value);
})
nearbyAPI.onPublishSuccess(message => {
  console.log(message);
});
nearbyAPI.onPublishFailed(message => {
  console.log(message);
});
nearbyAPI.onSubscribeSuccess(() => {});
nearbyAPI.onSubscribeFailed(() => {});

// To connect from Google API Client
nearbyAPI.connect(API_KEY);

// To check if the nearby API is connected.
nearbyAPI.isConnected((connected, error) => {
  console.log(connected);
});

// To disconnect later
nearbyAPI.disconnect();

// To publish to nearby devices
nearbyAPI.publish("Hello World!");

// To check if the nearby API is publishing.
nearbyAPI.isPublishing((publishing, error) => {
  console.log(publishing);
});

// To subscribe to nearby devices broadcasting
nearbyAPI.subscribe();

// To check if the nearby API is subscribing.
nearbyAPI.isSubscribing((subscribing, error) => {
  console.log(subscribing);
});

// To unpublish
nearbyAPI.unpublish();

// To unsubscribe
nearbyAPI.unsubscribe();

Running the Example

  • Install the dependencies in the root folder

    yarn

Generate an API Key from the Google Developer Console

  1. Go to the Google Developers Console.
  2. Create or select a project to register your application with.
  3. Click Continue to Enable the API.
  4. On the Credentials page, create a new API Key. (No key restrictions are needed for this example)
  5. 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 = [NSURL URLWithString:@"http://<IP-ADDRESS>:8081/index.bundle?platform=ios&dev=true"];
  • 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 after node_modules have been installed and you've attempted to run in Xcode.

react-native-nearby-api's People

Contributors

0x0ece avatar jacks205 avatar owlvark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-nearby-api's Issues

Duplicate symbol issue when building example

I get the following error when building the example app. Can't really figure where the symbols are beig duplicated. Any pointers?

duplicate symbol __ZN6google10AddLogSinkEPNS_7LogSinkE in:
    /Users/user/Library/Developer/Xcode/DerivedData/example-cgaryrzrmdqdxlhdvluwfugfneku/Build/Products/Debug-iphoneos/libReact.a(logging.o)
    /Users/user/Downloads/drivers/react-native-nearby-api/example/ios/Pods/NearbyMessages/Libraries/libGNSMessages.a(logging.o)
duplicate symbol __ZN6google13RemoveLogSinkEPNS_7LogSinkE in:
    /Users/user/Library/Developer/Xcode/DerivedData/example-cgaryrzrmdqdxlhdvluwfugfneku/Build/Products/Debug-iphoneos/libReact.a(logging.o)
    /Users/user/Downloads/drivers/react-native-nearby-api/example/ios/Pods/NearbyMessages/Libraries/libGNSMessages.a(logging.o)
ld: 2 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Install script fails on windows

I'm not sure if you intend on supporting windows, but I just thought I'd let you know this package fails when installing it into your project on windows.

It is a similar error to other packages that don't support windows. When running npm install or yarn install within your project on windows it throws the following error:

'scripts' is not recognized as an internal or external command," on windows.

The fix seems to be switching to a node script for running scripts/install.js as seen here. However looking at your install.js function, it probably would need some changes to be executable on windows.

'string' file not found

Hi,

I'm pretty new to RN development and have limited knowledge of IOS or Android.

Everything was well with the plugin and we have launched few times but somehow(quite suddenly) we are unable to build with develop and release schema.

I've tried setting Compile Source As to objective c++ as suggested here without much success
react-native-google-signin/google-signin#361

Help please
screen shot 2018-07-11 at 3 20 50 am
?
Cheers,

dead or alive? :)

hi

is this plugin maintained? i am asking because i do believe this plugin will get a lot of attention in the coming months ... or not ... based on it's state ... i am asking this because i see that the open issues are untouched for about 2 months now

thanks @jacks205 @0x0ece

Duplicate symbols for architecture

I have ran ./renameLogger.sh to resolve this issue but did not get to work as React-Native version 0.60+ do not contains the third-party folder. see details below;

"dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-nearby-api": "0.0.5"
  },

Currently running the example provided here. this works for IOS & Android on 0.56 of react-native.

Thanks.

Java.lang.NoClassDefFoundError: com.google.android.gms.nearby.messages.Message

Tried to use the module but doesn't seem to work with my config.

Any ideas?

MainApplication.java:


import com.facebook.react.ReactApplication;
import com.badfeatures.nearby.RNNearbyApiPackage;
import fr.bamlab.rnimageresizer.ImageResizerPackage;
import com.imagepicker.ImagePickerPackage;
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
//import io.invertase.firebase.admob.RNFirebaseAdMobPackage;
import com.mapbox.rctmgl.RCTMGLPackage;
import org.devio.rn.splashscreen.SplashScreenReactPackage;
import com.idehub.Billing.InAppBillingBridgePackage;
import com.react.rnspinkit.RNSpinkitPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.rnfs.RNFSPackage;
import com.rnziparchive.RNZipArchivePackage;
import com.tradle.react.UdpSocketsModule;
import com.peel.react.TcpSocketsModule;
import com.bitgo.randombytes.RandomBytesPackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.corbt.keepawake.KCKeepAwakePackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.wix.interactable.Interactable;

import com.facebook.react.modules.network.ReactCookieJarContainer;
import com.facebook.stetho.Stetho;
import okhttp3.OkHttpClient;
import com.facebook.react.modules.network.OkHttpClientProvider;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import java.util.concurrent.TimeUnit;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new RNNearbyApiPackage(),
            new ImageResizerPackage(),
            new ImagePickerPackage(),
            new RNFirebasePackage(),
            new RNFirebaseMessagingPackage(),
            new RNFirebaseAnalyticsPackage(),
            //new RNFirebaseAdMobPackage(),
            new RCTMGLPackage(),
            new SplashScreenReactPackage(),
            new InAppBillingBridgePackage(),
            new RNSpinkitPackage(),
            new RNFetchBlobPackage(),
            new RNDeviceInfo(),
            new RNFSPackage(),
            new RNZipArchivePackage(),
            new UdpSocketsModule(),
            new TcpSocketsModule(),
            new RandomBytesPackage(),
            new ReactNativeConfigPackage(),
            new VectorIconsPackage(),
            new KCKeepAwakePackage(),
            new Interactable()
      );
    }
  };

settings.gradle:

include ':react-native-nearby-api'
project(':react-native-nearby-api').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-nearby-api/android')

android/app/build.gradle:


dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile 'com.android.support:multidex:1.0.1'
    compile project(':react-native-nearby-api')
    compile project(':react-native-image-resizer')
    compile project(':react-native-image-picker')
    compile(project(':react-native-firebase')) {
        transitive = false
    }
	compile "com.google.firebase:firebase-core:11.6.0"
	compile "com.google.firebase:firebase-messaging:11.6.0"
	compile "com.google.firebase:firebase-analytics:11.6.0"
	//compile "com.google.firebase:firebase-ads:11.6.0"

    compile project(':mapbox-react-native-mapbox-gl')
    compile project(path: ':react-native-interactable')
    compile project(':react-native-splash-screen')
    compile project(':react-native-billing')
    compile 'com.facebook.stetho:stetho:1.3.1'
    compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'

    compile project(':react-native-spinkit')
    compile project(':react-native-fetch-blob')
    compile (project(':react-native-device-info')) {
        exclude group: "com.google.android.gms" 
    }
    compile project(':react-native-fs')
    compile project(':react-native-zip-archive')
    compile project(':react-native-udp')
    compile project(':react-native-tcp')
    compile project(':react-native-randombytes')
    compile project(':react-native-config')
    compile project(':react-native-vector-icons')
    compile project(':react-native-keep-awake')
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:0.51.0"  // From node_modules
	
	// Firebase dependencies
	compile ("com.google.android.gms:play-services-gcm:11.6.0") {
        force = true;
    }
	compile ("com.google.android.gms:play-services-base:11.6.0") {
		force = true;
	}
}

FIX: Follow developer practices for use of SDK

Overview

  • Follow dev guidelines for handling Nearby Messages for handling behavior

Resource

Respect user privacy

  • Help the user understand what data your app will expose to nearby users.
  • Don't publish sensitive information such as passwords and credit card numbers. Instead, pass authorization tokens or transaction identifiers.

Require an explicit user-initiated action to start Nearby

  • Don’t surprise the user. Require the user to perform an explicit action (a button tap, going to a section in your app, a special switch, etc) to activate Nearby.
    On both iOS and Android, calling Nearby for the first time will trigger a permission dialog from Nearby. Waiting for an explicit user action before invoking Nearby will help the user contextualize the dialog and associate it with your app's proximity-based feature.

Be mindful of battery consumption

Nearby's use of radios and sensors will cause your app to consume battery at 2.5-3.5 times the normal rate. To reduce battery usage, observe the following recommendations.

  • On Android, when publishing or subscribing with non-BLE devices, only invoke the Nearby Messages API from an Activity, and only keep that Activity running when the screen is on and your app is in the foreground. To do this, pass the Activity (or FragmentActivity) as an argument to the Context parameter of GoogleApiClient.Builder(). Invoking Nearby from a Service is only supported when subscribing to Bluetooth Low Energy (BLE) beacon messages.
  • On Android, in your app's Activity.onStop() callback, call Nearby.Messages.unpublish() and Nearby.Messages.unsubscribe() on any active publishes or subscribes, and then call GoogleApiClient.disconnect(). On iOS no action is necessary as this is handled automatically.
  • Make it easy for the user to stop active publishes and subscribes.
  • Do not publish or subscribe in the background without the user's knowledge.
    Use the right branding

We’ve provided a set of standard assets that you can use to represent Nearby in your app. Use only the following approved icons when referring to Nearby.

minimum Android and iOS versions

Hi

I am trying to identify what are the minimum versions of Android and iOS that can use these package ... where can i find some info related to this?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.