我无法在我的代码中启动 ble 管理器。我使用世博会。我尝试了很多在互联网上找到的解决方案,但没有一个对我有用。当我退出 blemanager.start 时,我的应用程序运行正常。我在 React native 中找不到任何关于 Promise 的文档……有我的代码。我真的希望你能帮助我。
import { Stylesheet, View, Text, Button, TouchableOpacity,FlatList, Alert,NativeAppEventEmitter } from 'react-native'
import donnee from '../Donnee/data'
import DataItem from './DataItem'
import FilmDetail from './FilmDetail';
import BleManager from 'react-native-ble-manager';
import React, { useState, useEffect } from 'react';
//import BleManager from 'react-native-ble-plx';
const width_proportion = '60%';
const Lwidth_proportion = '30%';
const maxwidth="100%";
const heightinside="12%";
const paddleft = '10%';
class Search extends React.Component {
componentDidMount() {
console.log('bluetooth scanner mounted');
NativeAppEventEmitter.addListener('BleManagerDiscoverPeripheral',(data) =>
{
let device = 'device found: ' + data.name + '(' + data.id + ')';
if(this.devices.indexOf(device) == -1) {
this.devices.push(device);
}
let newState = this.state;
newState.dataSource = newState.dataSource.cloneWithRows(this.devices);
this.setState(newState);
});
BleManager.start({ showAlert: false }).then(() => {
// Success code
console.log("Module initialized");
});
}
startScanning() {
console.log('start scanning');
}
render() {
return (
<View>
<View style={styles.entete}></View>
<View>
<TouchableOpacity style = {styles.filtrebtn} onPress={() => this.props.navigation.navigate("FilmDetail")}>
<Text style = {styles.textfiltre}>FILTRES</Text>
</TouchableOpacity>
<TouchableOpacity style = {styles.scan} onPress={() => this.startScanning()}>
<Text style = {styles.textscan}>SCAN</Text>
</TouchableOpacity>
</View>
<View>
<FlatList
data={donnee}
keyExtractor={(item) => item.id.toString()}
renderItem={({item}) =><DataItem donnees={item}/> } />
</View>
</View>
)
}
}
export default Search