权限,检出分支

This commit is contained in:
2025-11-25 14:41:21 +08:00
parent 9e8df74622
commit 29fc16f2ff
5 changed files with 47 additions and 16 deletions

View File

@@ -61,8 +61,12 @@ post_install do |installer|
# 开启定位权限支持
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_LOCATION=1'
# 如果你需要其他权限,也在这里加,比如相机:
# config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_CAMERA=1'
# 2. 相机 (Camera)
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_CAMERA=1'
# 3. 相册 (Photos)
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_PHOTOS=1'
end
end

View File

@@ -107,6 +107,6 @@ SPEC CHECKSUMS:
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b
PODFILE CHECKSUM: c2b648820a58f7013d9d17db812a119f8affaf6f
PODFILE CHECKSUM: 6416011b1bc721211379eaad259ff1cba3dbfad2
COCOAPODS: 1.16.2

View File

@@ -55,6 +55,8 @@
<key>NSCameraUsageDescription</key>
<string>需要访问您的相机以扫描二维码</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>需要访问您的相册以选择二维码图片进行识别</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>需要访问您的相册以选择二维码图片进行识别</string>
<key>CADisableMinimumFrameDurationOnPhone</key>

View File

@@ -125,19 +125,46 @@ class QrCodeController extends GetxController
}
void requestPermission() async {
final List<bool> results = await Future.wait([
requestCameraPermission(),
requestPhotosPermission(),
]);
if(Platform.isIOS){
var status = await Permission.camera.request();
if (status.isGranted) {
}
else if (status.isPermanentlyDenied) {
openAppSettings();
}
else {
showErrorToast('需要相机权限才能扫描二维码');
}
return;
}
final isCameraGranted = results[0];
final isPhotosGranted = results[1];
if (!isCameraGranted) {
final bool results = await requestCameraPermission();
if (!results) {
showErrorToast('相机权限未被授予,请到权限管理中打开');
}
if (!isPhotosGranted) {
}
void requestPhotoPermission() async {
if (Platform.isAndroid) {
final bool results = await requestPhotosPermission();
if (!results) {
showErrorToast('相册权限未被授予,请到权限管理中打开');
} else {
scanFromGallery();
}
}
if(Platform.isIOS){
var status = await Permission.photos.request();
print("权限状态: $status"); // 在控制台看这个输出
if (status.isGranted) {
scanFromGallery();
}
else if (status.isPermanentlyDenied) {
openAppSettings();
}
else {
showErrorToast('需要相册权限才能从相册中选择图片');
}
}
}
@@ -161,7 +188,6 @@ class QrCodeController extends GetxController
await StorageService.to.saveVehicleInfo(vehicle);
Get.back(result: true);
} on DioException catch (e) {
showErrorToast("网络请求失败,请稍后重试");
resumeScanner();
@@ -173,7 +199,6 @@ class QrCodeController extends GetxController
}
}
@override
void onClose() {
qrViewController?.dispose();

View File

@@ -27,7 +27,7 @@ class QrCodePage extends GetView<QrCodeController> {
),
actions: [
TextButton(
onPressed: controller.scanFromGallery,
onPressed: controller.requestPhotoPermission,
child: const Text(
'相册',
style: TextStyle(color: Colors.white, fontSize: 16),