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

After using BarcodeScannerController, iOS control panel flashlight icon gets disabled? #63

Closed
jonchui opened this issue Sep 21, 2017 · 2 comments

Comments

@jonchui
Copy link

jonchui commented Sep 21, 2017

REPRO STEPS:

  1. open BarcodeScannerController
  2. click the flash
  3. leave the scanner
  4. slide up on iOS control center

ACTUAL:
flashlight symbol is greyed out!
image

EXPECTED:
not greyed out

Code we use to call it:


let barcodeController = BarcodeScannerController()
        barcodeController.codeDelegate = self
        barcodeController.errorDelegate = self
        barcodeController.dismissalDelegate = self

 appDelegate = UIApplication.shared.delegate as! AppDelegate
            if UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft {
                appDelegate.barCodeScannerOrientation = .landscapeRight
            } else {
                appDelegate.barCodeScannerOrientation = .landscapeLeft
            }
            
            barcodeController.reset()
            
            if let strongself = self {
            
                if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) ==  AVAuthorizationStatus.authorized {
                    // Already Authorized
                    strongself.present(barcodeController, animated: true, completion: nil)
                } else if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) ==  AVAuthorizationStatus.notDetermined {
                    AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted: Bool) -> Void in
                        if granted == true {
                            // User granted
                            DispatchQueue.main.async {
                                strongself.present(barcodeController, animated: true, completion: nil)
                            }
                        }
                    })
                } else if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) ==  AVAuthorizationStatus.denied {
                    let alertController = UIAlertController(title: "Camera Access",
                                                            message: "The camera permission was not authorized. Please enable it in Settings to continue.",
                                                            preferredStyle: .alert)
                    
                    let settingsAction = UIAlertAction(title: "Settings", style: .default) { (alertAction) in
                        if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) {
                            UIApplication.shared.openURL(appSettings as URL)
                        }
                    }
                    alertController.addAction(settingsAction)
                    
                    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
                    alertController.addAction(cancelAction)
                    
                    strongself.present(alertController, animated: true, completion: nil)
                }
            }
@jonchui
Copy link
Author

jonchui commented Sep 21, 2017

FIXED

Found that we were retaining the BarcodeScannerController b/c of the scope - moved it into the block and all was good.

Thanks!

@jonchui jonchui closed this as completed Sep 21, 2017
@onmyway133
Copy link
Contributor

@jonchui glad you solved it 👍

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

No branches or pull requests

2 participants