99 lines
3.3 KiB
Dart
99 lines
3.3 KiB
Dart
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
import '../toast_utils.dart';
|
|
|
|
class IosPermissionHandler {
|
|
Future<void> requestAllPermissions() async {
|
|
await requestLocationPermission();
|
|
await requestBluetoothPermission();
|
|
await requestCameraPermission();
|
|
await requestStoragePermission();
|
|
await requestNotificationPermission();
|
|
await requestPhonePermission();
|
|
await requestMicrophonePermission();
|
|
}
|
|
|
|
Future<void> requestCameraToMicrophonePermissions() async {
|
|
await requestCameraPermission();
|
|
await requestMicrophonePermission();
|
|
}
|
|
|
|
Future<void> requestLocationPermission() async {
|
|
PermissionStatus status = await Permission.location.request();
|
|
if (status.isGranted) {
|
|
print("iOS: 位置权限已授予");
|
|
} else if (status.isPermanentlyDenied) {
|
|
print("iOS: 位置权限被永久拒绝,请前往设置开启");
|
|
} else {
|
|
print("iOS: 位置权限被拒绝");
|
|
}
|
|
}
|
|
|
|
Future<void> requestBluetoothPermission() async {
|
|
PermissionStatus status = await Permission.bluetooth.request();
|
|
if (status.isGranted) {
|
|
print("iOS: 蓝牙权限已授予");
|
|
} else {
|
|
print("iOS: 蓝牙权限被拒绝");
|
|
}
|
|
}
|
|
|
|
Future<void> requestCameraPermission() async {
|
|
PermissionStatus status = await Permission.camera.request();
|
|
if (status.isGranted) {
|
|
print("iOS: 摄像头权限已授予");
|
|
} else if (status.isPermanentlyDenied) {
|
|
print("iOS: 摄像头权限被永久拒绝,请前往设置开启");
|
|
ToastUtils.showError("权限被永久拒绝,请前往设置开启!");
|
|
openAppSettings();
|
|
} else {
|
|
print("iOS: 摄像头权限被拒绝");
|
|
ToastUtils.showError("权限被拒绝,可能会导致相关功能不可用!");
|
|
}
|
|
}
|
|
|
|
Future<void> requestStoragePermission() async {
|
|
PermissionStatus status = await Permission.photos.request();
|
|
if (status.isGranted) {
|
|
print("iOS: 存储权限已授予");
|
|
} else if (status.isPermanentlyDenied) {
|
|
print("iOS: 存储权限被永久拒绝,请前往设置开启");
|
|
} else {
|
|
print("iOS: 存储权限被拒绝");
|
|
}
|
|
}
|
|
|
|
Future<void> requestNotificationPermission() async {
|
|
PermissionStatus status = await Permission.notification.request();
|
|
if (status.isGranted) {
|
|
print("iOS: 通知权限已授予");
|
|
} else {
|
|
print("iOS: 通知权限被拒绝");
|
|
}
|
|
}
|
|
|
|
Future<void> requestPhonePermission() async {
|
|
PermissionStatus status = await Permission.phone.request();
|
|
if (status.isGranted) {
|
|
print("iOS: 电话权限已授予");
|
|
} else if (status.isPermanentlyDenied) {
|
|
print("iOS: 电话权限被永久拒绝,请前往设置开启");
|
|
} else {
|
|
print("iOS: 电话权限被拒绝");
|
|
}
|
|
}
|
|
|
|
static Future<void> requestMicrophonePermission() async {
|
|
PermissionStatus status = await Permission.microphone.request();
|
|
if (status.isGranted) {
|
|
print("iOS: 麦克风权限已授予");
|
|
} else if (status.isPermanentlyDenied) {
|
|
print("iOS: 麦克风权限被永久拒绝,请前往设置开启");
|
|
ToastUtils.showError("权限被永久拒绝,请前往设置开启!");
|
|
openAppSettings();
|
|
} else {
|
|
print("iOS: 麦克风限被拒绝");
|
|
ToastUtils.showError("权限被拒绝,可能会导致相关功能不可用!");
|
|
}
|
|
}
|
|
} |