Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
start(){
BleManager.start({showAlert: false})
.then( ()=>{
this.checkState();
console.log('Init the module success.');
}).catch(error=>{
console.log('Init the module fail.');
});
}
componentDidMount() {
AppState.addEventListener('change', this.handleAppStateChange);
BleManager.start({showAlert: false});
this.handlerDiscover = bleManagerEmitter.addListener('BleManagerDiscoverPeripheral', this.handleDiscoverPeripheral );
this.handlerStop = bleManagerEmitter.addListener('BleManagerStopScan', this.handleStopScan );
this.handlerDisconnect = bleManagerEmitter.addListener('BleManagerDisconnectPeripheral', this.handleDisconnectedPeripheral );
this.handlerUpdate = bleManagerEmitter.addListener('BleManagerDidUpdateValueForCharacteristic', this.handleUpdateValueForCharacteristic );
if (Platform.OS === 'android' && Platform.Version >= 23) {
PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
if (result) {
console.log("Permission is OK");
} else {
PermissionsAndroid.requestPermission(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
if (result) {
console.log("User accept");
constructor(props) {
super(props);
this.peripherals = [];
BleManager.enableBluetooth()
.then(() => {
console.log('Bluetooth is already enabled');
})
.catch((error) => {
Alert.alert('Enable bluetooth', 'You need to enable bluetooth to use this app.');
});
BleManager.start({showAlert: false})
.then(() => {
console.log('Module initialized');
});
if (Platform.OS === 'android' && Platform.Version >= 23) {
PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
if(!result){
PermissionsAndroid.requestPermission(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
if(!result){
Alert.alert('You need to give access to coarse location to use this app.');
}
});
}
});
}
}
useEffect(() => {
if (currentAppState === 'active') {
console.log('App has come to the foreground!', bleState);
BleManager.start({showAlert: true});
BleManager.checkState();
} else {
if (peripheral) {
changeCode({"type": "disconnect", "peripheral_id": peripheral.id});
BleManager.disconnect(peripheral.id);
}
setBleState("disconnected");
}
}, [currentAppState]);
start(){
BleManager.start({showAlert: false})
.then( ()=>{
console.log('Init the module');
});
}
componentDidMount() {
AppState.addEventListener('change', this.handleAppStateChange);
BleManager.start({showAlert: false});
this.handlerDiscover = bleManagerEmitter.addListener('BleManagerDiscoverPeripheral', this.handleDiscoverPeripheral );
this.handlerStop = bleManagerEmitter.addListener('BleManagerStopScan', this.handleStopScan );
if (Platform.OS === 'android' && Platform.Version >= 23) {
PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
if (result) {
console.log("Permission is OK");
} else {
PermissionsAndroid.requestPermission(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
if (result) {
console.log("User accept");
} else {
console.log("User refuse");
}
});
onCreate() {
this.props.availableDevicesChangeValue(true);
BleManager.start().then(() => {
BleManager.scan([], 10, false).then(() => {
NativeAppEventEmitter.addListener(
"BleManagerDiscoverPeripheral",
data => {
if (data.name === null) {
for (let i = 0; i < this.props.addedDevice.length; i += 1) {
if (data.id === this.props.addedDevice[i].macAddress) {
dup += 1;
}
}
for (let i = 0; i < devices.length; i += 1) {
if (data.id === devices[i].macAddress) {
dup1 += 1;
}
}
if (dup === 0) {