权限,检出分支
This commit is contained in:
@@ -61,8 +61,12 @@ post_install do |installer|
|
|||||||
# 开启定位权限支持
|
# 开启定位权限支持
|
||||||
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_LOCATION=1'
|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_LOCATION=1'
|
||||||
|
|
||||||
# 如果你需要其他权限,也在这里加,比如相机:
|
# 2. 相机 (Camera)
|
||||||
# config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_CAMERA=1'
|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_CAMERA=1'
|
||||||
|
|
||||||
|
# 3. 相册 (Photos)
|
||||||
|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PERMISSION_PHOTOS=1'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -107,6 +107,6 @@ SPEC CHECKSUMS:
|
|||||||
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
|
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
|
||||||
url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b
|
url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b
|
||||||
|
|
||||||
PODFILE CHECKSUM: c2b648820a58f7013d9d17db812a119f8affaf6f
|
PODFILE CHECKSUM: 6416011b1bc721211379eaad259ff1cba3dbfad2
|
||||||
|
|
||||||
COCOAPODS: 1.16.2
|
COCOAPODS: 1.16.2
|
||||||
|
|||||||
@@ -55,6 +55,8 @@
|
|||||||
<key>NSCameraUsageDescription</key>
|
<key>NSCameraUsageDescription</key>
|
||||||
<string>需要访问您的相机以扫描二维码</string>
|
<string>需要访问您的相机以扫描二维码</string>
|
||||||
<key>NSPhotoLibraryUsageDescription</key>
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>需要访问您的相册以选择二维码图片进行识别</string>
|
||||||
|
<key>NSPhotoLibraryAddUsageDescription</key>
|
||||||
<string>需要访问您的相册以选择二维码图片进行识别</string>
|
<string>需要访问您的相册以选择二维码图片进行识别</string>
|
||||||
|
|
||||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||||
|
|||||||
@@ -125,19 +125,46 @@ class QrCodeController extends GetxController
|
|||||||
}
|
}
|
||||||
|
|
||||||
void requestPermission() async {
|
void requestPermission() async {
|
||||||
final List<bool> results = await Future.wait([
|
if(Platform.isIOS){
|
||||||
requestCameraPermission(),
|
var status = await Permission.camera.request();
|
||||||
requestPhotosPermission(),
|
if (status.isGranted) {
|
||||||
]);
|
}
|
||||||
|
else if (status.isPermanentlyDenied) {
|
||||||
|
openAppSettings();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
showErrorToast('需要相机权限才能扫描二维码');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final isCameraGranted = results[0];
|
final bool results = await requestCameraPermission();
|
||||||
final isPhotosGranted = results[1];
|
if (!results) {
|
||||||
|
|
||||||
if (!isCameraGranted) {
|
|
||||||
showErrorToast('相机权限未被授予,请到权限管理中打开');
|
showErrorToast('相机权限未被授予,请到权限管理中打开');
|
||||||
}
|
}
|
||||||
if (!isPhotosGranted) {
|
}
|
||||||
showErrorToast('相册权限未被授予,请到权限管理中打开');
|
|
||||||
|
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);
|
await StorageService.to.saveVehicleInfo(vehicle);
|
||||||
|
|
||||||
Get.back(result: true);
|
Get.back(result: true);
|
||||||
|
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
showErrorToast("网络请求失败,请稍后重试");
|
showErrorToast("网络请求失败,请稍后重试");
|
||||||
resumeScanner();
|
resumeScanner();
|
||||||
@@ -173,7 +199,6 @@ class QrCodeController extends GetxController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
qrViewController?.dispose();
|
qrViewController?.dispose();
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class QrCodePage extends GetView<QrCodeController> {
|
|||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: controller.scanFromGallery,
|
onPressed: controller.requestPhotoPermission,
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'相册',
|
'相册',
|
||||||
style: TextStyle(color: Colors.white, fontSize: 16),
|
style: TextStyle(color: Colors.white, fontSize: 16),
|
||||||
|
|||||||
Reference in New Issue
Block a user