twostraws / CodeScanner

A SwiftUI view that is able to scan barcodes, QR codes, and more, and send back what was found.
MIT License
1.02k stars 293 forks source link

Add missing rights check #42

Closed xmanu closed 2 years ago

xmanu commented 2 years ago

After using this library in my project I found out, that there is currently no way to detect if the user has not granted permissions to the camera. This results in only a black screen for the CodeScannerView.

This PR adds an error case for missing rights, so the developer can update the UI to inform the user about the missing right. This might not be the cleanest implementation as it will always return the missingRights error for every error that occurred during initialization of init of AVCaptureDeviceInput. It works well for my case so far and is a purely additive change.

Do you mind merging this and releasing a new version @twostraws ? It has been a while since 1.0.7 and quite some new features were added (like viewfinder support)...

twostraws commented 2 years ago

Thank you for your contributor! I like the idea, but as you say sending back the same error for everything might be awfully confusing – is there a better option here?

xmanu commented 2 years ago

One could also pass through the error we got:

public enum ScanError: Error {
    case badInput, badOutput, initError(_ error: Error)
}

The user could then decide how to handle it...

twostraws commented 2 years ago

I think that seems like a more reasonable solution.

xmanu commented 2 years ago

Sorry for getting back to this so late (new 👶😉). I updated the PR to include the discussed changes!

twostraws commented 2 years ago

Thank you!