Merge branch 'release' of https://gitee.com/starlock-cn/app-starlock into release
This commit is contained in:
commit
ed442e1792
@ -110,7 +110,7 @@ class BlueManage {
|
|||||||
_connectionStateSubscription = bluetoothConnectDevice!.connectionState
|
_connectionStateSubscription = bluetoothConnectDevice!.connectionState
|
||||||
.listen((BluetoothConnectionState state) async {
|
.listen((BluetoothConnectionState state) async {
|
||||||
bluetoothConnectionState = state;
|
bluetoothConnectionState = state;
|
||||||
// AppLog.log("蓝牙连接状态:$state");
|
AppLog.log('蓝牙连接回调状态:$state');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,13 +386,33 @@ class BlueManage {
|
|||||||
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//尝试连接设备
|
||||||
|
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
//直接给蓝牙设备写入
|
||||||
|
Future<void> doNotSearchBLE(
|
||||||
|
String masAdds, ConnectStateCallBack connectStateCallBack) async {
|
||||||
|
await FlutterBluePlus.stopScan();
|
||||||
|
if (bluetoothConnectDevice == null ||
|
||||||
|
bluetoothConnectDevice?.remoteId.str != masAdds) {
|
||||||
|
bluetoothConnectDevice = BluetoothDevice.fromId(masAdds);
|
||||||
|
_initGetMtuSubscription();
|
||||||
|
_initListenConnectionState();
|
||||||
|
}
|
||||||
|
//尝试连接设备
|
||||||
|
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
//设备连接
|
||||||
|
Future<void> bluetoothDeviceConnect(BluetoothDevice bluetoothConnectDevice,
|
||||||
|
ConnectStateCallBack connectStateCallBack) async {
|
||||||
// 重连三次
|
// 重连三次
|
||||||
const int maxAttempts = 3;
|
const int maxAttempts = 3;
|
||||||
int attempt = 0;
|
int attempt = 0;
|
||||||
while (attempt < maxAttempts) {
|
while (attempt < maxAttempts) {
|
||||||
try {
|
try {
|
||||||
await bluetoothConnectDevice!.connect(timeout: 5.seconds);
|
await bluetoothConnectDevice.connect(timeout: 5.seconds);
|
||||||
break; // If the connection is successful, break the loop
|
break; // If the connection is successful, break the loop
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
AppLog.log('连接失败 重连了: $e');
|
AppLog.log('连接失败 重连了: $e');
|
||||||
@ -437,52 +457,6 @@ class BlueManage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//直接给蓝牙设备写入
|
|
||||||
Future<void> doNotSearchBLE(
|
|
||||||
String masAdds, ConnectStateCallBack connectStateCallBack) async {
|
|
||||||
await FlutterBluePlus.stopScan();
|
|
||||||
final BluetoothDevice device = BluetoothDevice.fromId(masAdds);
|
|
||||||
// 重连三次
|
|
||||||
const int maxAttempts = 3;
|
|
||||||
bool connected = false;
|
|
||||||
int attempt = 0;
|
|
||||||
while (attempt < maxAttempts && !connected) {
|
|
||||||
try {
|
|
||||||
await device.connect();
|
|
||||||
connected = true;
|
|
||||||
} catch (e, s) {
|
|
||||||
AppLog.log('连接失败 重连了: ${e.toString()} ${s.toString()}');
|
|
||||||
attempt++; // Increase the attempt count
|
|
||||||
if (attempt < maxAttempts) {
|
|
||||||
AppLog.log('重新尝试连接...');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!connected) {
|
|
||||||
connectStateCallBack(BluetoothConnectionState.disconnected);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bluetoothConnectDevice = device;
|
|
||||||
bluetoothConnectionState = BluetoothConnectionState.connected;
|
|
||||||
final List<BluetoothService> services =
|
|
||||||
await bluetoothConnectDevice!.discoverServices();
|
|
||||||
for (final BluetoothService service in services) {
|
|
||||||
if (service.uuid == _serviceIdConnect) {
|
|
||||||
for (final BluetoothCharacteristic characteristic
|
|
||||||
in service.characteristics) {
|
|
||||||
if (characteristic.characteristicUuid ==
|
|
||||||
_characteristicIdSubscription) {
|
|
||||||
_subScribeToCharacteristic(characteristic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
connectStateCallBack(BluetoothConnectionState.connected);
|
|
||||||
// writeCharacteristicWithResponse(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _subScribeToCharacteristic(
|
Future<void> _subScribeToCharacteristic(
|
||||||
BluetoothCharacteristic characteristic) async {
|
BluetoothCharacteristic characteristic) async {
|
||||||
final StreamSubscription<List<int>> subscription =
|
final StreamSubscription<List<int>> subscription =
|
||||||
|
|||||||
@ -29,22 +29,34 @@ class XSJPushProvider {
|
|||||||
debug: true,
|
debug: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
jpush.addEventHandler(
|
|
||||||
onReceiveNotification: (Map<String, dynamic> message) async {
|
|
||||||
AppLog.log('flutter onReceiveNotification: $message');
|
|
||||||
},
|
|
||||||
onOpenNotification: (Map<String, dynamic> message) async {
|
|
||||||
AppLog.log('flutter onOpenNotification: $message');
|
|
||||||
},
|
|
||||||
onReceiveMessage: (Map<String, dynamic> message) async {
|
|
||||||
AppLog.log('flutter onReceiveMessage: $message');
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
jpush.applyPushAuthority(
|
jpush.applyPushAuthority(
|
||||||
const NotificationSettingsIOS(sound: true, alert: true, badge: false),
|
const NotificationSettingsIOS(sound: true, alert: true, badge: false),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
addJPushEventHandler();
|
||||||
|
bindDeviceID();
|
||||||
|
}
|
||||||
|
|
||||||
|
//极光推送事件处理方法
|
||||||
|
void addJPushEventHandler() {
|
||||||
|
jpush.addEventHandler(
|
||||||
|
onReceiveNotification: (Map<String, dynamic> message) async {
|
||||||
|
AppLog.log('onReceiveNotification: $message');
|
||||||
|
},
|
||||||
|
onOpenNotification: (Map<String, dynamic> message) async {
|
||||||
|
AppLog.log('onOpenNotification: $message');
|
||||||
|
},
|
||||||
|
onReceiveMessage: (Map<String, dynamic> message) async {
|
||||||
|
AppLog.log('onReceiveMessage: $message');
|
||||||
|
},
|
||||||
|
onReceiveNotificationAuthorization: (Map<String, dynamic> message) async {
|
||||||
|
AppLog.log('onReceiveNotificationAuthorization: $message');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//绑定设备ID
|
||||||
|
Future<void> bindDeviceID() async {
|
||||||
try {
|
try {
|
||||||
AppLog.log('Fetching registration ID...');
|
AppLog.log('Fetching registration ID...');
|
||||||
final String rid = await jpush.getRegistrationID();
|
final String rid = await jpush.getRegistrationID();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user