diff --git a/ExampleProject/ExampleProject.xcodeproj/project.pbxproj b/ExampleProject/ExampleProject.xcodeproj/project.pbxproj index 4750530..fbc35c2 100644 --- a/ExampleProject/ExampleProject.xcodeproj/project.pbxproj +++ b/ExampleProject/ExampleProject.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ 3EC5EF8523C447EE0063A687 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3EC5EF8423C447EE0063A687 /* Preview Assets.xcassets */; }; 3EC5EF8823C447EE0063A687 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3EC5EF8623C447EE0063A687 /* LaunchScreen.storyboard */; }; 3EC5EF9223C448A20063A687 /* ModalScannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EC5EF9123C448A20063A687 /* ModalScannerView.swift */; }; - 4F737D9E2521C39F002E36F3 /* CarBode in Frameworks */ = {isa = PBXBuildFile; productRef = 4F737D9D2521C39F002E36F3 /* CarBode */; }; + 4F818A3825392854008491B6 /* CarBode in Frameworks */ = {isa = PBXBuildFile; productRef = 4F818A3725392854008491B6 /* CarBode */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -36,7 +36,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 4F737D9E2521C39F002E36F3 /* CarBode in Frameworks */, + 4F818A3825392854008491B6 /* CarBode in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -108,7 +108,7 @@ ); name = ExampleProject; packageProductDependencies = ( - 4F737D9D2521C39F002E36F3 /* CarBode */, + 4F818A3725392854008491B6 /* CarBode */, ); productName = ExampleProject; productReference = 3EC5EF7823C447EA0063A687 /* ExampleProject.app */; @@ -139,7 +139,7 @@ ); mainGroup = 3EC5EF6F23C447EA0063A687; packageReferences = ( - 4F737D9C2521C39F002E36F3 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */, + 4F818A3625392854008491B6 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */, ); productRefGroup = 3EC5EF7923C447EA0063A687 /* Products */; projectDirPath = ""; @@ -368,20 +368,20 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 4F737D9C2521C39F002E36F3 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */ = { + 4F818A3625392854008491B6 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/"; + repositoryURL = "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI"; requirement = { - branch = master; - kind = branch; + kind = upToNextMajorVersion; + minimumVersion = 2.1.1; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 4F737D9D2521C39F002E36F3 /* CarBode */ = { + 4F818A3725392854008491B6 /* CarBode */ = { isa = XCSwiftPackageProductDependency; - package = 4F737D9C2521C39F002E36F3 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */; + package = 4F818A3625392854008491B6 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */; productName = CarBode; }; /* End XCSwiftPackageProductDependency section */ diff --git a/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e2a618c..e786ae8 100644 --- a/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -3,11 +3,11 @@ "pins": [ { "package": "CarBode", - "repositoryURL": "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/", + "repositoryURL": "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI", "state": { - "branch": "master", - "revision": "ec65f4ac61e7a929eb86b3590b4e4c25c254e927", - "version": null + "branch": null, + "revision": "20af50e8a6dacbb11022148ead812348e6ee51c2", + "version": "2.1.1" } } ] diff --git a/ExampleProject/ExampleProject/ModalScannerView.swift b/ExampleProject/ExampleProject/ModalScannerView.swift index 7db2da4..fca0667 100644 --- a/ExampleProject/ExampleProject/ModalScannerView.swift +++ b/ExampleProject/ExampleProject/ModalScannerView.swift @@ -10,6 +10,45 @@ import SwiftUI import CarBode import AVFoundation +struct cameraFrame: Shape { + func path(in rect: CGRect) -> Path { + Path { path in + let width = rect.width + let height = rect.height + + path.addLines( [ + + CGPoint(x: 0, y: height * 0.25), + CGPoint(x: 0, y: 0), + CGPoint(x:width * 0.25, y:0) + ]) + + path.addLines( [ + + CGPoint(x: width * 0.75, y: 0), + CGPoint(x: width, y: 0), + CGPoint(x:width, y:height * 0.25) + ]) + + path.addLines( [ + + CGPoint(x: width, y: height * 0.75), + CGPoint(x: width, y: height), + CGPoint(x:width * 0.75, y: height) + ]) + + path.addLines( [ + + CGPoint(x:width * 0.25, y: height), + CGPoint(x:0, y: height), + CGPoint(x:0, y:height * 0.75) + + ]) + + } + } +} + struct ModalScannerView: View { @State var barcodeValue = "" @State var torchIsOn = false @@ -36,9 +75,9 @@ struct ModalScannerView: View { } }) { if cameraPosition == .back{ - Text("Swicth Camera to Front") + Text("Switch Camera to Front") }else{ - Text("Swicth Camera to Back") + Text("Switch Camera to Back") } } @@ -58,6 +97,7 @@ struct ModalScannerView: View { mockBarCode: .constant(BarcodeData(value:"My Test Data", type: .qr)) ){ print("BarCodeType =",$0.type.rawValue, "Value =",$0.value) + barcodeValue = $0.value } onDraw: { print("Preview View Size = \($0.cameraPreviewView.bounds)") @@ -65,15 +105,20 @@ struct ModalScannerView: View { let lineColor = UIColor.green let fillColor = UIColor(red: 0, green: 1, blue: 0.2, alpha: 0.4) - //Draw Barcode corner $0.draw(lineWidth: 1, lineColor: lineColor, fillColor: fillColor) }.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading) + .overlay(cameraFrame() + .stroke(lineWidth: 5) + .frame(width: 500, height: 250) + .foregroundColor(.blue)) Spacer() Text(barcodeValue) + + Spacer() }.alert(isPresented: $showingAlert) { Alert(title: Text("Found Barcode"), message: Text("\(barcodeValue)"), dismissButton: .default(Text("Close"))) diff --git a/README.md b/README.md index 1c4125e..d06bbba 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The preferred way of installing SwiftUIX is via the [Swift Package Manager](http 1. In Xcode, open your project and navigate to **File** → **Swift Packages** → **Add Package Dependency...** 2. Paste the repository URL (`https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI`) and click **Next**. -3. For **Rules**, select **Branch** (with branch set to `2.1.1` ). +3. For **Rules**, select **Branch** (with branch set to `2.1.2` ). 4. Click **Finish**. # Example project @@ -280,6 +280,7 @@ CBBarcodeView(data: ..... , CarBode welcomes contributions in the form of GitHub issues and pull-requests. ## Changelog + - 2.1.2 When scan on difference barcode scanner will ignore the delay time - 2.1.1 Fixed bugs - 2.1.0 You can draw a box around the barcode - 2.0.1 Fixed bugs diff --git a/Sources/CarBode/CameraPreview.swift b/Sources/CarBode/CameraPreview.swift index 970ed0a..8f98ed4 100644 --- a/Sources/CarBode/CameraPreview.swift +++ b/Sources/CarBode/CameraPreview.swift @@ -32,6 +32,8 @@ public class CameraPreview: UIView { var torchLightIsOn: Bool = false var removeFrameTimer: Timer? + + var lastScannedBarcode: BarcodeData? init() { super.init(frame: .zero) @@ -256,9 +258,16 @@ extension CameraPreview: AVCaptureMetadataOutputObjectsDelegate { func foundBarcode(_ barcode: BarcodeData) { let now = Date() - if now.timeIntervalSince(lastTime) >= scanInterval { + + //When scan on difference barcode scanner will ignore the delay time + if lastScannedBarcode?.value != barcode.value { lastTime = now onFound?(barcode) + lastScannedBarcode = barcode + }else if now.timeIntervalSince(lastTime) >= scanInterval { + lastTime = now + onFound?(barcode) + lastScannedBarcode = barcode } } }