gpt4 book ai didi

ios - 在iOS上 flutter 蓝牙问题

转载 作者:行者123 更新时间:2023-12-01 21:41:06 24 4
gpt4 key购买 nike

使用flutter blue plugin(0.5.0版)时,我遇到了问题。
我的Bluetooth设备仅连接一次,直到关闭iPhone上的Bluetooth并再次打开它之后,我才能再次连接。
这是实验的视频。
https://drive.google.com/file/d/1pQW4JFQI5R_zcxF3wfozT6Ru2AY2KxBm/view?usp=sharing
我无法使用最新的插件版本,因为该项目很旧。
此问题仅在ios中发生。
这是我的连接代码:

_connect(BluetoothDevice d) async {
device = d;
// Connect to device
deviceConnection = _flutterBlue
.connect(device, timeout: const Duration(seconds: 4))
.listen(
null,
onDone: _disconnect,
);

// Update the connection state immediately
device.state.then((s) {
setState(() {
deviceState = s;
});
});

// Subscribe to connection changes
deviceStateSubscription = device.onStateChanged().listen((s) {
if (mounted)
setState(() {
deviceState = s;
});
if (s == BluetoothDeviceState.connected) {
device.discoverServices().then((s) {
var bservice = s
.where((r) =>
r.uuid
.toString()
.toLowerCase()
.contains("0000ffe0-0000-1000-8000-00805f9b34fb"))
.first;
if (bservice != null) {
var char = bservice.characteristics
.where((c) =>
c.uuid
.toString()
.toLowerCase()
.contains("0000ffe4-0000-1000-8000-00805f9b34fb"))
.first;
if (char != null) {
_setNotification(char);
}
}
bservice = s
.where((r) =>
r.uuid
.toString()
.toLowerCase()
.contains("00001808-0000-1000-8000-00805f9b34fb"))
.first;
if (bservice != null) {
var char = bservice.characteristics
.where((c) =>
c.uuid
.toString()
.toLowerCase()
.contains("00002a18-0000-1000-8000-00805f9b34fb"))
.first;
if (char != null) {
_setNotification(char);
}
}

setState(() {
//Accu-Answer isaw Service UUID="0000ffe0-0000-1000-8000-00805f9b34fb"
//Accu-Answer isaw Characteristics UUID="0000ffe4-0000-1000-8000-00805f9b34fb"
//YASEE Service UUID="00001808-0000-1000-8000-00805f9b34fb"
//YASEE Characteristics UUID="00002a18-0000-1000-8000-00805f9b34fb"

// var bservice=s.where((r) =>r.uuid.toString().toLowerCase().contains("0000ffe0-0000-1000-8000-00805f9b34fb")).first;//Accu-Answer
// var bservice=s.where((r) =>r.uuid.toString().toLowerCase().contains("00001808-0000-1000-8000-00805f9b34fb")).first;//YASEE
for (int i = 0; i < s.length; i++) {
var bservice = s[i];
var tmpUUID = bservice.uuid.toString().toLowerCase();

if (tmpUUID == "0000ffe0-0000-1000-8000-00805f9b34fb") {
var char = bservice.characteristics
.where((c) =>
c.uuid
.toString()
.toLowerCase()
.contains("0000ffe4-0000-1000-8000-00805f9b34fb"))
.first;
if (char != null) {
_setNotification(char);
}
break;
} else if (tmpUUID == "00001808-0000-1000-8000-00805f9b34fb") {
var char = bservice.characteristics
.where((c) =>
c.uuid
.toString()
.toLowerCase()
.contains("00002a18-0000-1000-8000-00805f9b34fb"))
.first;
if (char != null) {
_setNotification(char);
}
break;
}
}

//services = s;
});
});
}
});}
我正在 iPhone 6和ios版本 12.4.7上进行测试

最佳答案

我对flutter blue lib有很多问题,因此决定尝试另一个库,但我的问题消失了。传输代码应该没有问题。 API有点不同,但是示例很好而扎实。
这是我使用的软件包,我强烈推荐它:https://pub.dev/packages/flutter_ble_lib

关于ios - 在iOS上 flutter 蓝牙问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62529775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com