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

fix: codeScanner unsupported ios version error handing #3175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/docs/guides/CODE_SCANNING.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,23 @@ Interleaved2of5 (ITF) barcodes are supported by both, Android and iOS, where And

ITF-14 is a sub type of interleaved2of5 which always encodes 14 characters. The ITF-14 type is only supported by iOS. If you want to have the restriction to 14 characters in Android as well, you have to handle this in your own code.

## Supported Code Types

| Code Type | iOS | Android |
|----------------------|--------------------|--------------------|
| qr | :white_check_mark: | :white_check_mark: |
| aztec | :white_check_mark: | :white_check_mark: |
| data-matrix | :white_check_mark: | :white_check_mark: |
| ean-13 | :white_check_mark: | :white_check_mark: |
| ean-8 | :white_check_mark: | :white_check_mark: |
| code-128 | :white_check_mark: | :white_check_mark: |
| code-39 | :white_check_mark: | :white_check_mark: |
| code-93 | :white_check_mark: | :white_check_mark: |
| codabar | 15.4+ | :white_check_mark: |
| itf | :white_check_mark: | :white_check_mark: |
| itf-14 | :white_check_mark: | :white_check_mark: |
| upc-e | :white_check_mark: | :white_check_mark: |
| upc-a | :white_check_mark: | :white_check_mark: |
| pdf-417 | :white_check_mark: | :white_check_mark: |

#### 🚀 Next section: [Frame Processors](frame-processors)
2 changes: 1 addition & 1 deletion example/src/CodeScannerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function CodeScannerPage({ navigation }: Props): React.ReactElement {

// 5. Initialize the Code Scanner to scan QR codes and Barcodes
const codeScanner = useCodeScanner({
codeTypes: ['qr', 'ean-13'],
codeTypes: ['qr', 'ean-13', 'codabar'],
onCodeScanned: onCodeScanned,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AVFoundation
import Foundation

extension AVMetadataObject.ObjectType {
init(withString string: String) throws {
init?(withString string: String) throws {
switch string {
case "code-128":
self = .code128
Expand All @@ -25,7 +25,7 @@ extension AVMetadataObject.ObjectType {
if #available(iOS 15.4, *) {
self = .codabar
} else {
throw CameraError.codeScanner(.codeTypeNotSupported(codeType: string))
return nil
}
return
case "ean-13":
Expand Down
2 changes: 1 addition & 1 deletion package/ios/Core/Types/CodeScannerOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct CodeScannerOptions: Equatable {

init(fromJsValue dictionary: NSDictionary) throws {
if let codeTypes = dictionary["codeTypes"] as? [String] {
self.codeTypes = try codeTypes.map { value in
self.codeTypes = try codeTypes.compactMap { value in
return try AVMetadataObject.ObjectType(withString: value)
}
} else {
Expand Down
Loading