Here’s how I use it, hope it could help
const { updateCharacteristic } = this.props
const connectedDevice = await manager.connectToDevice(device.id)
const services = await connectedDevice.discoverAllServicesAndCharacteristics()
const characteristic = await this.getServicesAndCharacteristics(services)
getServicesAndCharacteristics(device) {
return new Promise((resolve, reject) => {
device.services().then(services => {
const characteristics = []
services.forEach((service, i) => {
service.characteristics().then(c => {
characteristics.push(c)
if (i === services.length - 1) {
const temp = characteristics.reduce(
(acc, current) => {
return [...acc, ...current]
},
[]
)
const dialog = temp.find(
characteristic =>
characteristic.isWritableWithoutResponse
)
if (!dialog) {
reject('No writable characteristic')
}
resolve(dialog)
}
})
})
})
})
}
Best regards.
If you are writing React-Native class with ES6, following format will be followed. It includes life cycle methods of RN for the class making network calls.
<!-- language: lang-js -->
import React, {Component} from 'react';
import {
AppRegistry, StyleSheet, View, Text, Image
ToastAndroid
} from 'react-native';
import * as Progress from 'react-native-progress';
export default class RNClass extends Component{
constructor(props){
super(props);
this.state= {
uri: this.props.uri,
loading:false
}
}
renderLoadingView(){
return(
<View style={{justifyContent:'center',alignItems:'center',flex:1}}>
<Progress.Circle size={30} indeterminate={true} />
<Text>
Loading Data...
</Text>
</View>
);
}
renderLoadedView(){
return(
<View>
</View>
);
}
fetchData(){
fetch(this.state.uri)
.then((response) => response.json())
.then((result)=>{
})
.done();
this.setState({
loading:true
});
this.renderLoadedView();
}
componentDidMount(){
this.fetchData();
}
render(){
if(!this.state.loading){
return(
this.renderLoadingView()
);
}
else{
return(
this.renderLoadedView()
);
}
}
}
var style = StyleSheet.create({
});