Closed Android-yzhang closed 5 years ago
蓝牙设备(model: miaomiaoce.sensor_ht.t1)米家后台设置了"扩展程序退出保持连接" 否,但是还是发现有的时候不能断开(具体表现为退出插件之后很长时间连接都被保持,蓝牙设备无法用lightblue等app连上)。所以我们在退出插件之前自动吊了一次断开MHBluetooth.disconnectDevice()。之前测试发现还好,使用最新的米家测试发现又有不能断开的情况。
@badsdy @Android-yzhang 你们调用MHBluetooth.disconnectDevice()
的时机是什么时候?附上代码吧
@Android-yzhang @badsdy Maybe you run MHBluetooth.disconnectDevice()
at the wrong time. It is related to life cycle of React Native. You should run MHBluetooth.disconnectDevice()
truly before existing the plugin, where closeCurrentPage is.
Wrong Way:
// MainPage.js
componentWillMount() {
MHBluetooth.disconnectDevice();
}
Right Way:
// index.ios.js
var navigationBarRouteMapper = {
LeftButton: function (route, navigator, index, navState) {
if (route.renderNavLeftComponent) {
return route.renderNavLeftComponent(route, navigator, index, navState);
} else {
var previousRoute = navState.routeStack[index - 1];
return (
<View>
<ImageButton
source={{ uri: MHPluginSDK.uriNaviBackButtonImage, scale: PixelRatio.get() }}
onPress={() => {
MHBluetooth.disconnectDevice(); // right here before closeCurrentPage
MHPluginSDK.closeCurrentPage();
} else {
navigator.pop();
}
}}
style={[{ width: 29, height: 29, tintColor: '#000000' }, route.navLeftButtonStyle]}
/>
</View>
);
}
}.bind(this),
};
Check the log below when exist plugin, u will get what happen.
@LiuMengzhou 很早就改成这样写了,在index.ios.js中控制, 但还是有不能断开的情况
是的,我也是这样写,但还是有断不开的情况
@Copypeng
在退出插件时,调用MHBluetooth.disconnectDevice();存在一定几率不能断开硬件