更新ios蓝牙权限
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
@@ -201,69 +204,92 @@ Future<Map> checkBlueToothPermissin() async {
|
||||
var bluetoothConnectGranted;
|
||||
var locationGranted;
|
||||
|
||||
try {
|
||||
// 先显示权限说明弹窗(同屏显示)
|
||||
bool bluetoothScanPermanentlyDenied =
|
||||
await Permission.bluetoothScan.isPermanentlyDenied;
|
||||
bool bluetoothConnectPermanentlyDenied =
|
||||
await Permission.bluetoothConnect.isPermanentlyDenied;
|
||||
bool locationPermanentlyDenied =
|
||||
await Permission.location.isPermanentlyDenied;
|
||||
|
||||
if (bluetoothScanPermanentlyDenied ||
|
||||
bluetoothConnectPermanentlyDenied ||
|
||||
locationPermanentlyDenied) {
|
||||
return data; // 直接返回,不再弹窗申请
|
||||
if (Platform.isIOS) {
|
||||
PermissionStatus isBleGranted = await Permission.bluetooth.request();
|
||||
if (isBleGranted.isGranted) {
|
||||
// startBluetoothScanning();
|
||||
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
|
||||
data = {
|
||||
'bluetoothScanGranted': true,
|
||||
'bluetoothConnectGranted': true,
|
||||
};
|
||||
} else {
|
||||
try {
|
||||
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
|
||||
} catch (e) {
|
||||
TopSlideNotification.show(Get.context!,
|
||||
text: "蓝牙权限未开启,请在设置中开启蓝牙权限".tr,
|
||||
textColor: themeController.currentColor.sc9);
|
||||
}
|
||||
}
|
||||
if (userInfoController.initLocationpermission == 1) {
|
||||
return data;
|
||||
} else {
|
||||
try {
|
||||
// 先显示权限说明弹窗(同屏显示)
|
||||
bool bluetoothScanPermanentlyDenied =
|
||||
await Permission.bluetoothScan.isPermanentlyDenied;
|
||||
bool bluetoothConnectPermanentlyDenied =
|
||||
await Permission.bluetoothConnect.isPermanentlyDenied;
|
||||
bool locationPermanentlyDenied =
|
||||
await Permission.location.isPermanentlyDenied;
|
||||
|
||||
if (bluetoothScanPermanentlyDenied ||
|
||||
bluetoothConnectPermanentlyDenied ||
|
||||
locationPermanentlyDenied) {
|
||||
return data; // 直接返回,不再弹窗申请
|
||||
}
|
||||
if (userInfoController.initLocationpermission == 1) {
|
||||
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
||||
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
||||
locationGranted = await Permission.location.isGranted;
|
||||
data = {
|
||||
'bluetoothScanGranted': bluetoothScanGranted,
|
||||
'bluetoothConnectGranted': bluetoothConnectGranted,
|
||||
'locationGranted': locationGranted,
|
||||
};
|
||||
return data;
|
||||
}
|
||||
showPermissionInfoDialog(
|
||||
Get.context!,
|
||||
CommonVariables().bluetoothpermissionInfo,
|
||||
);
|
||||
show = true;
|
||||
|
||||
// 检查并请求权限
|
||||
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
||||
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
||||
locationGranted = await Permission.location.isGranted;
|
||||
|
||||
if (!bluetoothScanGranted ||
|
||||
!bluetoothConnectGranted ||
|
||||
!locationGranted) {
|
||||
await [
|
||||
Permission.bluetoothScan,
|
||||
Permission.bluetoothConnect,
|
||||
Permission.location,
|
||||
].request();
|
||||
|
||||
// 更新权限状态
|
||||
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
||||
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
||||
locationGranted = await Permission.location.isGranted;
|
||||
}
|
||||
|
||||
data = {
|
||||
'bluetoothScanGranted': bluetoothScanGranted,
|
||||
'bluetoothConnectGranted': bluetoothConnectGranted,
|
||||
'locationGranted': locationGranted,
|
||||
};
|
||||
return data;
|
||||
}
|
||||
showPermissionInfoDialog(
|
||||
Get.context!,
|
||||
CommonVariables().bluetoothpermissionInfo,
|
||||
);
|
||||
show = true;
|
||||
|
||||
// 检查并请求权限
|
||||
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
||||
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
||||
locationGranted = await Permission.location.isGranted;
|
||||
|
||||
if (!bluetoothScanGranted || !bluetoothConnectGranted || !locationGranted) {
|
||||
await [
|
||||
Permission.bluetoothScan,
|
||||
Permission.bluetoothConnect,
|
||||
Permission.location,
|
||||
].request();
|
||||
|
||||
// 更新权限状态
|
||||
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
||||
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
||||
locationGranted = await Permission.location.isGranted;
|
||||
}
|
||||
|
||||
data = {
|
||||
'bluetoothScanGranted': bluetoothScanGranted,
|
||||
'bluetoothConnectGranted': bluetoothConnectGranted,
|
||||
'locationGranted': locationGranted,
|
||||
};
|
||||
|
||||
// 通知 web 端
|
||||
WebviewTestController webviewTestController = Get.find();
|
||||
// webviewTestController.web.jsbridge?.dart.updatePermission(data);
|
||||
} catch (e) {
|
||||
ef.log("蓝牙权限:$e");
|
||||
} finally {
|
||||
if (show) {
|
||||
Navigator.of(Get.context!, rootNavigator: true).pop();
|
||||
// 通知 web 端
|
||||
WebviewTestController webviewTestController = Get.find();
|
||||
// webviewTestController.web.jsbridge?.dart.updatePermission(data);
|
||||
} catch (e) {
|
||||
ef.log("蓝牙权限:$e");
|
||||
} finally {
|
||||
if (show) {
|
||||
Navigator.of(Get.context!, rootNavigator: true).pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart' as edm;
|
||||
import 'package:easydevice/easydevice.dart';
|
||||
@@ -63,7 +64,7 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
web.jsbridge!.bind((bridge) {
|
||||
var minible = Minibleapp(bridge: bridge);
|
||||
// ef.kvroot.devicelist.listen((x) {});
|
||||
bridge.sdk.updateDeviceRoute((args) async {
|
||||
bridge.sdk.updateDeviceRoute((args) async {
|
||||
ef.log('updateDeviceRoute: $args');
|
||||
selectDevice['blueToothStatus'] = bluetooth;
|
||||
Get.toNamed("${args[0]}", arguments: selectDevice);
|
||||
@@ -236,11 +237,21 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
if (data == null || data.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
if (!data['bluetoothScanGranted'] ||
|
||||
!data['bluetoothConnectGranted'] ||
|
||||
!data['locationGranted']) {
|
||||
if (Platform.isIOS) {
|
||||
if (!data['bluetoothScanGranted'] ||
|
||||
!data['bluetoothConnectGranted']) {
|
||||
return false;
|
||||
}
|
||||
} else if (Platform.isAndroid) {
|
||||
if (!data['bluetoothScanGranted'] ||
|
||||
!data['bluetoothConnectGranted'] ||
|
||||
!data['locationGranted']) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
ef.log("[网页加载失败]:$e");
|
||||
@@ -565,12 +576,14 @@ class WebviewTestView extends GetComponent<WebviewTestController> {
|
||||
// return (controller.ready.value && (MainPageBBottomChange.getCurrentIndex() == 2))
|
||||
return (controller.ready.value)
|
||||
? controller.web.build()
|
||||
: Center(child:CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
themeController.currentColor.sc1,
|
||||
),
|
||||
),);
|
||||
: Center(
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
themeController.currentColor.sc1,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user