我无法运行 blemanager.start,因为承诺拒绝 id:0 null 不是一个对象



我无法在代码中启动ble管理器。我用世博会。我尝试了很多我在网上找到的解决方案,但没有一个适合我。当我出去的时候,经理。启动我的应用程序正确运行。我没有在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

expo无法与ble-manager一起工作。您需要通过运行

来使用本机包。
npx react-native init AwesomeProject

你需要MAC而不是一个窗口

最新更新