我已在 flutter 中使用 Permission Handler 包请求权限,但我收到的所有请求均被授予 false 请求。仅将 Permission.bluetooth.isGranted 设为 true。
await [
Permission.bluetooth,
Permission.bluetoothScan,
Permission.bluetoothConnect,
Permission.bluetoothAdvertise,
].request();
bool blueScanStatus = await Permission.bluetoothScan.isGranted;
// debugPrint(
// "\n==============\n | Bluetooth Scan Permissions: $blueScanStatus | \n==============\n");
bool blueAdvStatus = await Permission.bluetoothAdvertise.isGranted;
/* debugPrint(
"\n==============\n | Bluetooth Advertise Permissions: $blueAdvStatus | \n==============\n");*/
bool blueStatus = await Permission.bluetooth.isGranted;
/* debugPrint(
"\n==============\n | Bluetooth Permissions: $blueStatus | \n==============\n");*/
bool blueConnectStatus = await Permission.bluetoothConnect.isGranted;
该代码在 Android 上运行良好,但仅在 iOS 上出现问题。我需要在 Info.plist 上添加一些内容吗?在此处输入图像描述
经过几次研究后这个问题已经解决,我得出的结论是ios没有BluetoothScan、BluetoohAdvertise和BluetoohConnect。 iOS 仅支持蓝牙 Permission 方法。所以我修改了下面提到的代码。
Map<Permission, PermissionStatus> blePermissions = await [
Permission.bluetooth,
if (Platform.isAndroid) Permission.bluetoothScan,
if (Platform.isAndroid) Permission.bluetoothConnect,
if (Platform.isAndroid) Permission.bluetoothAdvertise,
].request();