Ver código fonte

Fix getting camera permissions

flutter-beta
Guy Kogus 5 anos atrás
pai
commit
1dbe37c775
2 arquivos alterados com 9 adições e 9 exclusões
  1. +7
    -3
      ios/Classes/QRView.swift
  2. +2
    -6
      lib/src/qr_code_scanner.dart

+ 7
- 3
ios/Classes/QRView.swift Ver arquivo

@@ -125,7 +125,11 @@ public class QRView:NSObject,FlutterPlatformView {
arguments.forEach { arg in arguments.forEach { arg in
allowedBarcodeTypes.append( QRCodeTypes[arg]!) allowedBarcodeTypes.append( QRCodeTypes[arg]!)
} }
MTBBarcodeScanner.requestCameraPermission(success: { permissionGranted in
MTBBarcodeScanner.requestCameraPermission(success: { [weak self] permissionGranted in
guard let self = self else { return }

self.channel.invokeMethod("onPermissionSet", arguments: permissionGranted)

if permissionGranted { if permissionGranted {
do { do {
try self.scanner?.startScanning(with: self.cameraFacing, resultBlock: { [weak self] codes in try self.scanner?.startScanning(with: self.cameraFacing, resultBlock: { [weak self] codes in
@@ -169,8 +173,8 @@ public class QRView:NSObject,FlutterPlatformView {


}) })
} catch { } catch {
let error = FlutterError(code: "unknown-error", message: "Unable to start scanning", details: nil)
return result(error)
let scanError = FlutterError(code: "unknown-error", message: "Unable to start scanning", details: error)
result(scanError)
} }
} else { } else {
let error = FlutterError(code: "cameraPermission", message: "Permission denied to access the camera", details: nil) let error = FlutterError(code: "cameraPermission", message: "Permission denied to access the camera", details: nil)


+ 2
- 6
lib/src/qr_code_scanner.dart Ver arquivo

@@ -199,13 +199,9 @@ class QRViewController {
case 'onPermissionSet': case 'onPermissionSet':
await getSystemFeatures(); // if we have no permission all features will not be avaible await getSystemFeatures(); // if we have no permission all features will not be avaible
if (call.arguments != null) { if (call.arguments != null) {
if (call.arguments as bool) {
_hasPermissions = true;
} else {
_hasPermissions = false;
}
_hasPermissions = call.arguments as bool;
if (onPermissionSet != null) { if (onPermissionSet != null) {
onPermissionSet(this, call.arguments as bool);
onPermissionSet(this, _hasPermissions);
} }
} }
break; break;


Carregando…
Cancelar
Salvar