bluevery is an easier library that aims to reduce the frustration of ble communication on react-native.
This library is a wrapper library that uses react-native-ble-manager.
- Wrapping procedural processes in implicit knowledge
- Manages and provides the state required for BLE connectivity
- Allows developers to implement hooks on a per-peripheral basis
- Extensive options to mitigate BLE connection failures
- Retries, timeouts and useful callbacks etc...
$ yarn add bluevery
and don't forget install peerDependencies
Edit your app AndroidManifest.xml
AndroidManifest.xml
<!-- π¨ Keep only the permissions used in your app π¨ -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- π¨ Keep only the permissions used in your app π¨ -->
Edit your app Podfile
then run pod install
Podfile
target 'YourAppProject' do
# add the below
permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
end
Edit your app Info.plist
Info.plist
<!-- π¨ Keep only the permissions used in your app π¨ -->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>EDIT YOUR TEXT</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>EDIT YOUR TEXT</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>EDIT YOUR TEXT</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>EDIT YOUR TEXT</string>
<!-- π¨ Keep only the permissions used in your app π¨ -->
bluevery is a singleton. First of all, please run init in your application.
import { bluevery } from 'bluevery'
await bluevery.init({
__DEBUG: 'bluevery,bluevery:*',
});
The recommendation is to create hooks for each peripheral. Please refer to the example hooks.
bluevery manages and provides the necessary state for ble connection. You can use the state in a hooks style (State is read-only).
import { useBlueveryState } from 'bluevery';
const MyBleScreen: React.VFC<Props> = (props) => {
const bleState = useBlueveryState();
return {
// your JSX
}
}
See the following interface for state definitions.
bluevery is only able to wrap some methods of react-native-ble-manager.
If there are any methods you need, implement them in bluevery. Please contribute! Or use the original react-native-ble-manager as an interim process without bluevery!
Pass the debug namespace into the init options.
https://github.com/visionmedia/debug#environment-variables
await bluevery.init({
__DEBUG: 'bluevery,bluevery:*',
// ...other options
})
It is recommended that do not log in the production. You should avoid memory leaks and unnecessary process on users' client.
await bluevery.init({
__DEBUG: IS_DEVELOPMENT ? 'bluevery,bluevery:*' : undefined,
// ...other options
})