Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on iOS 13 when permission denied #127

Closed
xvrh opened this issue Apr 25, 2020 · 5 comments · Fixed by #134
Closed

Crash on iOS 13 when permission denied #127

xvrh opened this issue Apr 25, 2020 · 5 comments · Fixed by #134

Comments

@xvrh
Copy link
Contributor

xvrh commented Apr 25, 2020

The app crashes on the line 140 of QrReader.swift

    // catch?
    let input = try! AVCaptureDeviceInput.init(device: captureDevice)

on iOS 13 when the Camera permission if denied by the user.

2020-04-25 21:51:42.472234+0200 Runner[35675:9811013] Initialized TensorFlow Lite runtime.
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=AVFoundationErrorDomain Code=-11852 "Cannot use Back Camera" UserInfo={NSLocalizedFailureReason=This app is not authorized to use Back Camera., AVErrorDeviceKey=<AVCaptureFigVideoDevice: 0x10870d7c0 [Back Camera][com.apple.avfoundation.avcapturedevice.built-in_video:0]>, NSLocalizedDescription=Cannot use Back Camera}: file /Users/xavier/.pub-cache/hosted/pub.dartlang.org/qr_mobile_vision-1.0.1+1/ios/Classes/QrReader.swift, line 140
2020-04-25 21:51:42.494777+0200 Runner[35675:9811013] Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=AVFoundationErrorDomain Code=-11852 "Cannot use Back Camera" UserInfo={NSLocalizedFailureReason=This app is not authorized to use Back Camera., AVErrorDeviceKey=<AVCaptureFigVideoDevice: 0x10870d7c0 [Back Camera][com.apple.avfoundation.avcapturedevice.built-in_video:0]>, NSLocalizedDescription=Cannot use Back Camera}: file /Users/xavier/.pub-cache/hosted/pub.dartlang.org/qr_mobile_vision-1.0.1+1/ios/Classes/QrReader.swift, line 140

Screenshot 2020-04-25 at 21 58 17

@lovelessX
Copy link
Contributor

I, too, am having this issue. Also on iOS 12.

@rohnsht
Copy link

rohnsht commented May 11, 2020

Same here app crashes when permission is denied. Is there any fix for this?

@rohnsht
Copy link

rohnsht commented May 11, 2020

The issue is there because let input = try! AVCaptureDeviceInput.init(device: captureDevice) this code throws an exception when the user denies Camera permission. Here is fix for this issue:

Inside QrReader.swift file that can be found inside Pods/Development Pods/qr_mobile_vision/.../classes make the following changes:

  1. add throws to the constructor
init(targetWidth: Int, targetHeight: Int, textureHandler: TextureHandler, options: VisionBarcodeDetectorOptions, qrCallback: @escaping (_:String) -> Void) throws { 
 // ....
}
  1. Remove ! from this line
    let input = try AVCaptureDeviceInput.init(device: captureDevice)

Now inside SwiftQrMobileVisionPlugin.swift modify this code:

do{
          reader = try QrReader(
            targetWidth: targetWidth,
            targetHeight: targetHeight,
            textureHandler: texture,
            options: options) { [unowned self] qr in
              self.channel.invokeMethod("qrRead", arguments: qr)
          }
      }catch {
        print(error.localizedDescription)
        result(FlutterError(code: "QRREADER_ERROR", message: "noPermission", details: ""))
        return
      }

@xvrh
Copy link
Contributor Author

xvrh commented May 11, 2020

@rohnsht I opened a pull request with your instructions.

@rcagantas
Copy link

Any workaround on this? It's blocking a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants