Support
version | react-native version | Xcode version |
---|---|---|
3.0.0+ | 0.63.0+ | 12+ |
Installing dependencies into a bare React Native project
$ npm install --save react-native-ble-plx react-native-permissions
# --- or ---
$ yarn add react-native-ble-plx react-native-permissions
Setup
$ npm install --save @diviven/payment
# --- or ---
$ yarn add @diviven/payment
Configuration & Installation
Expo
- Make sure your Expo project is ejected (formerly: detached). You can read how to do it here and here. (only for expo)
- Follow steps for iOS/Android.
example setup)
iOS (npm install --save react-native-ble-plx
- Enter
ios
folder and runpod update
- Add
NSBluetoothAlwaysUsageDescription
ininfo.plist
file. (it is a requirement since iOS 13) - If you want to support background mode:
- In your application target go to
Capabilities
tab and enableUses Bluetooth LE Accessories
inBackground Modes
section. - Pass
restoreStateIdentifier
andrestoreStateFunction
toBleManager
constructor.
- In your application target go to
example setup)
Android (-
npm install --save react-native-ble-plx
-
In top level
build.gradle
make sure that min SDK version is at least 18:buildscript { ext { ... minSdkVersion = 21 ...
-
In
build.gradle
make sure to add jitpack repository to known repositories:allprojects { repositories { ... maven { url 'https://www.jitpack.io' } } }
-
(Optional) In
AndroidManifest.xml
, add Bluetooth permissions and update<uses-sdk/>
:<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- Add this line if your application always requires BLE. More info can be found on: https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#permissions --> <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> ...
Troubleshooting
Problems with Proguard
Add this to your app/proguard-rules.pro
-dontwarn com.polidea.reactnativeble.**
🆘 Manual linking
Because this package targets React Native 0.63.0+, you probably won't need to link it manually. Otherwise if it's not the case, follow these additional instructions. You also need to manual link the module on Windows when using React Native Windows prior to 0.63:
👀 See manual linking instructions
iOS
Add this line to your ios/Podfile
file, then run pod install
.
target 'YourAwesomeProject' do
# …
pod 'RNPermissions', :path => '../node_modules/react-native-permissions'
end
Android
- Add the following lines to
android/settings.gradle
:
include ':react-native-permissions'
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
- Add the implementation line to the dependencies in
android/app/build.gradle
:
dependencies {
// ...
implementation project(':react-native-permissions')
}
How TO use
import {CheckPermissions, StartScanDevices} from '@diviven/payment'
...
CheckPermissions().then(()=>{
StartScanDevices()
.then(devices => {
console.log(devices);
})
.catch(err => {
console.log(err);
});
});