Skip to content

Commit 4d81e65

Browse files
Merge branch 'development'
2 parents e31e80d + 94f64a2 commit 4d81e65

File tree

8 files changed

+90
-69
lines changed

8 files changed

+90
-69
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
22
include ':capacitor-android'
3-
project(':capacitor-android').projectDir = new File('../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/android/capacitor')
3+
project(':capacitor-android').projectDir = new File('../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/android/capacitor')
44

55
include ':capacitor-app'
6-
project(':capacitor-app').projectDir = new File('../../node_modules/.pnpm/@capacitor+app@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/app/android')
6+
project(':capacitor-app').projectDir = new File('../../node_modules/.pnpm/@capacitor+app@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/app/android')
77

88
include ':capacitor-barcode-scanner'
99
project(':capacitor-barcode-scanner').projectDir = new File('../../plugin/android')
1010

1111
include ':capacitor-haptics'
12-
project(':capacitor-haptics').projectDir = new File('../../node_modules/.pnpm/@capacitor+haptics@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/haptics/android')
12+
project(':capacitor-haptics').projectDir = new File('../../node_modules/.pnpm/@capacitor+haptics@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/haptics/android')
1313

1414
include ':capacitor-keyboard'
15-
project(':capacitor-keyboard').projectDir = new File('../../node_modules/.pnpm/@capacitor+keyboard@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/keyboard/android')
15+
project(':capacitor-keyboard').projectDir = new File('../../node_modules/.pnpm/@capacitor+keyboard@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/keyboard/android')
1616

1717
include ':capacitor-status-bar'
18-
project(':capacitor-status-bar').projectDir = new File('../../node_modules/.pnpm/@capacitor+status-bar@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/status-bar/android')
18+
project(':capacitor-status-bar').projectDir = new File('../../node_modules/.pnpm/@capacitor+status-bar@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/status-bar/android')

example-app/ios/App/Podfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/ios/scripts/pods_helpers'
1+
require_relative '../../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/ios/scripts/pods_helpers'
22

33
platform :ios, '14.0'
44
use_frameworks!
@@ -9,13 +9,13 @@ use_frameworks!
99
install! 'cocoapods', :disable_input_output_paths => true
1010

1111
def capacitor_pods
12-
pod 'Capacitor', :path => '../../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/ios'
13-
pod 'CapacitorCordova', :path => '../../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/ios'
14-
pod 'CapacitorApp', :path => '../../../node_modules/.pnpm/@capacitor+app@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/app'
12+
pod 'Capacitor', :path => '../../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/ios'
13+
pod 'CapacitorCordova', :path => '../../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/ios'
14+
pod 'CapacitorApp', :path => '../../../node_modules/.pnpm/@capacitor+app@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/app'
1515
pod 'CapacitorBarcodeScanner', :path => '../../../plugin'
16-
pod 'CapacitorHaptics', :path => '../../../node_modules/.pnpm/@capacitor+haptics@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/haptics'
17-
pod 'CapacitorKeyboard', :path => '../../../node_modules/.pnpm/@capacitor+keyboard@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/keyboard'
18-
pod 'CapacitorStatusBar', :path => '../../../node_modules/.pnpm/@capacitor+status-bar@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/status-bar'
16+
pod 'CapacitorHaptics', :path => '../../../node_modules/.pnpm/@capacitor+haptics@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/haptics'
17+
pod 'CapacitorKeyboard', :path => '../../../node_modules/.pnpm/@capacitor+keyboard@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/keyboard'
18+
pod 'CapacitorStatusBar', :path => '../../../node_modules/.pnpm/@capacitor+status-bar@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/status-bar'
1919
end
2020

2121
target 'App' do

example-app/ios/App/Podfile.lock

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
PODS:
2-
- Capacitor (7.0.0-alpha.2):
2+
- Capacitor (7.0.0-rc.0):
33
- CapacitorCordova
4-
- CapacitorApp (6.0.0-rc.1):
4+
- CapacitorApp (7.0.0-rc.0):
55
- Capacitor
6-
- CapacitorBarcodeScanner (2.0.0):
6+
- CapacitorBarcodeScanner (2.0.1):
77
- Capacitor
8-
- OSBarcodeLib (~> 1.1.0)
9-
- CapacitorCordova (7.0.0-alpha.2)
10-
- CapacitorHaptics (6.0.0-rc.1):
8+
- OSBarcodeLib (~> 1.1.3)
9+
- CapacitorCordova (7.0.0-rc.0)
10+
- CapacitorHaptics (7.0.0-rc.0):
1111
- Capacitor
12-
- CapacitorKeyboard (6.0.0-rc.1):
12+
- CapacitorKeyboard (7.0.0-rc.0):
1313
- Capacitor
14-
- CapacitorStatusBar (6.0.0-rc.1):
14+
- CapacitorStatusBar (7.0.0-rc.0):
1515
- Capacitor
16-
- OSBarcodeLib (1.1.0)
16+
- OSBarcodeLib (1.1.3)
1717

1818
DEPENDENCIES:
19-
- "Capacitor (from `../../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/ios`)"
20-
- "CapacitorApp (from `../../../node_modules/.pnpm/@capacitor+app@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/app`)"
19+
- "Capacitor (from `../../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/ios`)"
20+
- "CapacitorApp (from `../../../node_modules/.pnpm/@capacitor+app@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/app`)"
2121
- CapacitorBarcodeScanner (from `../../../plugin`)
22-
- "CapacitorCordova (from `../../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/ios`)"
23-
- "CapacitorHaptics (from `../../../node_modules/.pnpm/@capacitor+haptics@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/haptics`)"
24-
- "CapacitorKeyboard (from `../../../node_modules/.pnpm/@capacitor+keyboard@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/keyboard`)"
25-
- "CapacitorStatusBar (from `../../../node_modules/.pnpm/@capacitor+status-bar@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/status-bar`)"
22+
- "CapacitorCordova (from `../../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/ios`)"
23+
- "CapacitorHaptics (from `../../../node_modules/.pnpm/@capacitor+haptics@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/haptics`)"
24+
- "CapacitorKeyboard (from `../../../node_modules/.pnpm/@capacitor+keyboard@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/keyboard`)"
25+
- "CapacitorStatusBar (from `../../../node_modules/.pnpm/@capacitor+status-bar@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/status-bar`)"
2626

2727
SPEC REPOS:
2828
trunk:
2929
- OSBarcodeLib
3030

3131
EXTERNAL SOURCES:
3232
Capacitor:
33-
:path: "../../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/ios"
33+
:path: "../../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/ios"
3434
CapacitorApp:
35-
:path: "../../../node_modules/.pnpm/@capacitor+app@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/app"
35+
:path: "../../../node_modules/.pnpm/@capacitor+app@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/app"
3636
CapacitorBarcodeScanner:
3737
:path: "../../../plugin"
3838
CapacitorCordova:
39-
:path: "../../../node_modules/.pnpm/@[email protected]alpha.2_@[email protected]alpha.2/node_modules/@capacitor/ios"
39+
:path: "../../../node_modules/.pnpm/@[email protected]rc.0_@[email protected]rc.0/node_modules/@capacitor/ios"
4040
CapacitorHaptics:
41-
:path: "../../../node_modules/.pnpm/@capacitor+haptics@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/haptics"
41+
:path: "../../../node_modules/.pnpm/@capacitor+haptics@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/haptics"
4242
CapacitorKeyboard:
43-
:path: "../../../node_modules/.pnpm/@capacitor+keyboard@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/keyboard"
43+
:path: "../../../node_modules/.pnpm/@capacitor+keyboard@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/keyboard"
4444
CapacitorStatusBar:
45-
:path: "../../../node_modules/.pnpm/@capacitor+status-bar@6.0.0-rc.1_@[email protected]alpha.2/node_modules/@capacitor/status-bar"
45+
:path: "../../../node_modules/.pnpm/@capacitor+status-bar@7.0.0-rc.0_@[email protected]rc.0/node_modules/@capacitor/status-bar"
4646

4747
SPEC CHECKSUMS:
48-
Capacitor: 58fbb66cfc0c3f37ed647b4e4f0fcdb94997db86
49-
CapacitorApp: 649eca1980ddb28d43177bc78b252123e243b848
50-
CapacitorBarcodeScanner: ab47851bc95b78003606089d18dd43467b2e70f6
51-
CapacitorCordova: c5fa9fad682ebccd4d5f457ef7901427ee9471b1
52-
CapacitorHaptics: b004f0eb5b1cbef124889ccf745679f3aa9568ef
53-
CapacitorKeyboard: 683563ad6b13c1a46bfc710d49b4621570feef48
54-
CapacitorStatusBar: 31febfff4331f2e800847abdac79d64f04eb4206
55-
OSBarcodeLib: ced133bc1ec073636e18c6a0553d0a5c4b90cf17
48+
Capacitor: e79eb426d47f13ee0e2fdaff9ef0e9990db34a48
49+
CapacitorApp: a50750608d62c0ff1fe7f33d38365dd915bb0f31
50+
CapacitorBarcodeScanner: 67bdccc07abc05c3993e83da0196fedef7f5d508
51+
CapacitorCordova: 8f4f6826f0b40f7b506eb13b832039b7140a88b4
52+
CapacitorHaptics: 51c7ca77b24d5448bd716db4f6d5b47302ab9566
53+
CapacitorKeyboard: 342c56b26934429f58ec25fdbe9d4b6553969f8d
54+
CapacitorStatusBar: 89f0dc71f6544cef1dd250dfdb347a25547532b4
55+
OSBarcodeLib: f2e981270a64faf476cb790864262b29ab8cd68a
5656

57-
PODFILE CHECKSUM: 4a39645c1d85edfd261058f6704cdf9dc05d2bb8
57+
PODFILE CHECKSUM: 7bd915a9b237ee006f510f6135ab6eb2a3e55593
5858

5959
COCOAPODS: 1.16.2

example-app/src/pages/Home.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
import { IonButton, IonContent, IonHeader, IonInput, IonPage, IonTitle, IonToolbar } from '@ionic/react';
22
import './Home.css';
33
import { useState } from 'react';
4-
import { CapacitorBarcodeScanner, CapacitorBarcodeScannerTypeHint } from '@capacitor/barcode-scanner';
4+
import { CapacitorBarcodeScanner, CapacitorBarcodeScannerAndroidScanningLibrary, CapacitorBarcodeScannerCameraDirection, CapacitorBarcodeScannerScanOrientation, CapacitorBarcodeScannerTypeHint } from '@capacitor/barcode-scanner';
55

66
const Home: React.FC = () => {
77
const [scannerResult, setScannerResult] = useState<string>('No Data...');
88

99
const scanBarcode = async () => {
10-
const result = await CapacitorBarcodeScanner.scanBarcode({
11-
hint: CapacitorBarcodeScannerTypeHint.ALL
12-
});
13-
setScannerResult(result.ScanResult);
10+
try {
11+
const result = await CapacitorBarcodeScanner.scanBarcode({
12+
hint: CapacitorBarcodeScannerTypeHint.ALL,
13+
scanInstructions: "Please scan a barcode",
14+
scanButton: true,
15+
scanText: "Scan",
16+
cameraDirection: CapacitorBarcodeScannerCameraDirection.BACK,
17+
scanOrientation: CapacitorBarcodeScannerScanOrientation.ADAPTIVE,
18+
android: {
19+
scanningLibrary: CapacitorBarcodeScannerAndroidScanningLibrary.ZXING
20+
}
21+
});
22+
setScannerResult(result.ScanResult);
23+
} catch (error) {
24+
if (error instanceof Error) {
25+
setScannerResult("Error: " + error.message);
26+
} else {
27+
setScannerResult("Error: Unknown error");
28+
}
29+
}
1430
};
1531

1632
return (

plugin/CapacitorBarcodeScanner.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ Pod::Spec.new do |s|
1313
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
1414
s.ios.deployment_target = '14.0'
1515
s.dependency 'Capacitor'
16-
s.dependency 'OSBarcodeLib', '~> 1.1.0'
16+
s.dependency 'OSBarcodeLib', '~> 1.1.3'
1717
s.swift_version = '5.1'
1818
end

plugin/android/src/main/java/com/capacitorjs/barcodescanner/OSBarcodePlugin.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,18 @@ class CapacitorBarcodeScannerPlugin : Plugin() {
3030
fun scanBarcode(call: PluginCall) {
3131
val hint = call.getInt("hint")
3232
val scanInstructions = call.getString("scanInstructions")
33-
val scanButton = call.getBoolean("scanButton", false)
34-
val scanText = call.getString("scanText", "")
33+
val scanButton = call.getBoolean("scanButton", false) ?: false
34+
val scanText = call.getString("scanText", "") ?: ""
3535
val cameraDirection = call.getInt("cameraDirection")
36-
37-
val nativeOptions = call.getObject("native")
38-
39-
val scanOrientation = nativeOptions?.getInteger("scanOrientation")
40-
val androidScanningLibrary = nativeOptions?.getJSObject("android")?.getString("scanningLibrary")
36+
val scanOrientation = call.getInt("scanOrientation")
37+
val androidScanningLibrary = call.getObject("android")?.getString("scanningLibrary")
4138

4239
val parameters = OSBARCScanParameters(
4340
scanInstructions = scanInstructions,
4441
cameraDirection = cameraDirection,
4542
scanOrientation = scanOrientation,
46-
scanButton = scanButton!!,
47-
scanText = scanText!!,
43+
scanButton = scanButton,
44+
scanText = scanText,
4845
hint = hint,
4946
androidScanningLibrary = androidScanningLibrary
5047
)

plugin/ios/Plugin/CapacitorBarcodeScannerPlugin.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public class CapacitorBarcodeScannerPlugin: CAPPlugin {
2222
}
2323

2424
guard let manager = self.manager else {
25-
call.reject("Capacitor bridge or viewController is not initialized.")
25+
call.sendError(with: OSBarcodeError.bridgeNotInitialized)
2626
return
2727
}
2828

2929
guard let argumentsData = try? JSONSerialization.data(withJSONObject: call.jsObjectRepresentation),
3030
let scanArguments = try? JSONDecoder().decode(OSBarcodeScanArgumentsModel.self, from: argumentsData) else {
31-
call.reject("Error decoding scan arguments")
31+
call.sendError(with: OSBarcodeError.scanInputArgumentsIssue)
3232
return
3333
}
3434

@@ -37,12 +37,20 @@ public class CapacitorBarcodeScannerPlugin: CAPPlugin {
3737
let scannedBarcode = try await manager.scanBarcode(with: scanArguments.scanInstructions, scanArguments.scanButtonText, scanArguments.cameraDirection, and: scanArguments.scanOrientation)
3838
call.resolve(["ScanResult": scannedBarcode])
3939
} catch OSBARCManagerError.cameraAccessDenied {
40-
call.reject("Camera access denied")
40+
call.sendError(with: OSBarcodeError.cameraAccessDenied)
4141
} catch OSBARCManagerError.scanningCancelled {
42-
call.reject("Scanning cancelled")
42+
call.sendError(with: OSBarcodeError.scanningCancelled)
4343
} catch {
44-
call.reject("An unexpected error occurred: \(error.localizedDescription)")
44+
call.sendError(with: OSBarcodeError.scanningError)
4545
}
4646
}
4747
}
4848
}
49+
50+
extension CAPPluginCall {
51+
52+
func sendError(with error: OSBarcodeError) {
53+
self.reject(error.errorDescription, error.errorCode)
54+
}
55+
56+
}

plugin/ios/Plugin/OSBarcodeError.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ enum OSBarcodeError: Int, CustomNSError, LocalizedError {
1111
case scanningCancelled = 6
1212
case cameraAccessDenied = 7
1313
case scanInputArgumentsIssue = 8
14+
case bridgeNotInitialized = 13
1415

15-
var errorDescription: String? {
16+
var errorDescription: String {
1617
switch self {
1718
case .scanningError: return "Error while trying to scan code."
1819
case .scanningCancelled: return "Couldn’t scan because the process was cancelled."
1920
case .cameraAccessDenied: return "Couldn’t scan because camera access wasn’t provided. Check your camera permissions and try again."
2021
case .scanInputArgumentsIssue: return "Scanning parameters are invalid."
22+
case .bridgeNotInitialized: return "Capacitor bridge or viewController is not initialized."
2123
}
2224
}
23-
24-
var errorDictionary: [String: String] {
25-
[
26-
OSBarcodeErrorLabels.code: "\(OSBarcodeErrorLabels.codeFormat)\(String(format: "%04d", self.rawValue))",
27-
OSBarcodeErrorLabels.message: self.errorDescription ?? ""
28-
]
25+
26+
var errorCode: String {
27+
return "\(OSBarcodeErrorLabels.codeFormat)\(String(format: "%04d", self.rawValue))"
2928
}
29+
3030
}

0 commit comments

Comments
 (0)