From ea441b3100fb2c0e5d5877d6580bb58104b56b08 Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 17:16:40 +0900 Subject: [PATCH 01/10] Add SwiftUI support for QRScanner with iOS 14+ minimum deployment target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add QRScannerSwiftUIView: UIViewRepresentable wrapper for QRScannerView - Create QRScannerSwiftUISample: SwiftUI demo application - Update minimum iOS deployment target from 10.0 to 14.0 across all targets - Integrate SwiftUI sample into QRScanner.xcworkspace - Implement modern Swift concurrency with MainActor instead of DispatchQueue - Add comprehensive SwiftUI usage documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- MercariQRScanner.podspec | 2 +- Package.swift | 2 +- QRScanner.xcodeproj/project.pbxproj | 8 +- .../contents.xcworkspacedata | 3 + QRScanner/QRScannerSwiftUIView.swift | 132 +++++++ .../QRScannerSample.xcodeproj/project.pbxproj | 4 +- .../project.pbxproj | 349 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcschemes/QRScannerSwiftUISample.xcscheme | 78 ++++ .../AppIcon.appiconset/Contents.json | 98 +++++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 30 ++ .../QRScannerSwiftUISample/ContentView.swift | 77 ++++ .../QRScannerSwiftUISample/Info.plist | 43 +++ .../QRScannerSwiftUIApp.swift | 10 + SwiftUI_Usage.md | 151 ++++++++ 17 files changed, 1002 insertions(+), 6 deletions(-) create mode 100644 QRScanner/QRScannerSwiftUIView.swift create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.pbxproj create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/xcshareddata/xcschemes/QRScannerSwiftUISample.xcscheme create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/Contents.json create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample/Base.lproj/LaunchScreen.storyboard create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample/ContentView.swift create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample/Info.plist create mode 100644 QRScannerSwiftUISample/QRScannerSwiftUISample/QRScannerSwiftUIApp.swift create mode 100644 SwiftUI_Usage.md diff --git a/MercariQRScanner.podspec b/MercariQRScanner.podspec index b443c1d..e795c99 100644 --- a/MercariQRScanner.podspec +++ b/MercariQRScanner.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.license = "MIT" s.author = { "hitsubunnu" => "idhitsu@gmail.com" } s.swift_version = "5.0" - s.ios.deployment_target = "10.0" + s.ios.deployment_target = "14.0" s.source = { :git => "https://github.com/mercari/QRScanner.git", :tag => s.version } s.source_files = "QRScanner/*.swift", "QRScanner/**/*.swift" s.resources = "QRScanner/*.xcassets" diff --git a/Package.swift b/Package.swift index 2bfeddc..d9af112 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "QRScanner", platforms: [ - .iOS(.v10), + .iOS(.v14), ], products: [ .library( diff --git a/QRScanner.xcodeproj/project.pbxproj b/QRScanner.xcodeproj/project.pbxproj index 2889e7a..d6bfdde 100644 --- a/QRScanner.xcodeproj/project.pbxproj +++ b/QRScanner.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 16D0D5EE23570BC800A2EC78 /* QRScanner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16D0D5E423570BC800A2EC78 /* QRScanner.framework */; }; 16D0D5F523570BC800A2EC78 /* QRScanner.h in Headers */ = {isa = PBXBuildFile; fileRef = 16D0D5E723570BC800A2EC78 /* QRScanner.h */; settings = {ATTRIBUTES = (Public, ); }; }; 43820BFF256A29DD0046AC78 /* Bundle+Module.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43820BFE256A29DD0046AC78 /* Bundle+Module.swift */; }; + 43820C00256A29DD0046AC79 /* QRScannerSwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43820BFF256A29DD0046AC79 /* QRScannerSwiftUIView.swift */; }; 76124403238BCEA70020466C /* QRScannerViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76124402238BCEA70020466C /* QRScannerViewTests.swift */; }; 76E80674238BB26E0000C667 /* QRScannerSpyDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76E80673238BB26E0000C667 /* QRScannerSpyDelegate.swift */; }; /* End PBXBuildFile section */ @@ -37,6 +38,7 @@ 16D0D5ED23570BC800A2EC78 /* QRScannerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QRScannerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 16D0D5F423570BC800A2EC78 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43820BFE256A29DD0046AC78 /* Bundle+Module.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Module.swift"; sourceTree = ""; }; + 43820BFF256A29DD0046AC79 /* QRScannerSwiftUIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QRScannerSwiftUIView.swift"; sourceTree = ""; }; 76124402238BCEA70020466C /* QRScannerViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRScannerViewTests.swift; sourceTree = ""; }; 76E80673238BB26E0000C667 /* QRScannerSpyDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRScannerSpyDelegate.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -84,6 +86,7 @@ 16D0D5E723570BC800A2EC78 /* QRScanner.h */, 43820BFE256A29DD0046AC78 /* Bundle+Module.swift */, 16A16402235710D80032684C /* QRScannerView.swift */, + 43820BFF256A29DD0046AC79 /* QRScannerSwiftUIView.swift */, 16A16404235711240032684C /* QRScannerError.swift */, 16D0D5E823570BC800A2EC78 /* Info.plist */, 16A16406235712360032684C /* Images.xcassets */, @@ -231,6 +234,7 @@ 16A16405235711240032684C /* QRScannerError.swift in Sources */, 16A16403235710D80032684C /* QRScannerView.swift in Sources */, 43820BFF256A29DD0046AC78 /* Bundle+Module.swift in Sources */, + 43820C00256A29DD0046AC79 /* QRScannerSwiftUIView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -306,7 +310,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -364,7 +368,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; diff --git a/QRScanner.xcworkspace/contents.xcworkspacedata b/QRScanner.xcworkspace/contents.xcworkspacedata index 7a0f0ce..75a5519 100644 --- a/QRScanner.xcworkspace/contents.xcworkspacedata +++ b/QRScanner.xcworkspace/contents.xcworkspacedata @@ -48,4 +48,7 @@ + + diff --git a/QRScanner/QRScannerSwiftUIView.swift b/QRScanner/QRScannerSwiftUIView.swift new file mode 100644 index 0000000..b0d32a3 --- /dev/null +++ b/QRScanner/QRScannerSwiftUIView.swift @@ -0,0 +1,132 @@ +import SwiftUI + +// MARK: - QRScannerSwiftUIView +public struct QRScannerSwiftUIView: UIViewRepresentable { + + // MARK: - Configuration + public struct Configuration { + public let focusImage: UIImage? + public let focusImagePadding: CGFloat + public let animationDuration: Double + public let isBlurEffectEnabled: Bool + + public init( + focusImage: UIImage? = nil, + focusImagePadding: CGFloat = 8.0, + animationDuration: Double = 0.5, + isBlurEffectEnabled: Bool = false + ) { + self.focusImage = focusImage + self.focusImagePadding = focusImagePadding + self.animationDuration = animationDuration + self.isBlurEffectEnabled = isBlurEffectEnabled + } + } + + // MARK: - Properties + private let configuration: Configuration + private let onSuccess: (String) -> Void + private let onFailure: (QRScannerError) -> Void + private let onTorchActiveChange: ((Bool) -> Void)? + @Binding private var isScanning: Bool + @Binding private var torchActive: Bool + + // MARK: - Initializers + public init( + configuration: Configuration = Configuration(), + isScanning: Binding = .constant(true), + torchActive: Binding = .constant(false), + onSuccess: @escaping (String) -> Void, + onFailure: @escaping (QRScannerError) -> Void, + onTorchActiveChange: ((Bool) -> Void)? = nil + ) { + self.configuration = configuration + self._isScanning = isScanning + self._torchActive = torchActive + self.onSuccess = onSuccess + self.onFailure = onFailure + self.onTorchActiveChange = onTorchActiveChange + } + + // MARK: - UIViewRepresentable + public func makeUIView(context: Context) -> QRScannerView { + let qrScannerView = QRScannerView() + let input = QRScannerView.Input( + focusImage: configuration.focusImage, + focusImagePadding: configuration.focusImagePadding, + animationDuration: configuration.animationDuration, + isBlurEffectEnabled: configuration.isBlurEffectEnabled + ) + qrScannerView.configure(delegate: context.coordinator, input: input) + context.coordinator.qrScannerView = qrScannerView + + if isScanning { + qrScannerView.startRunning() + } + + return qrScannerView + } + + public func updateUIView(_ uiView: QRScannerView, context: Context) { + if isScanning { + uiView.startRunning() + } else { + uiView.stopRunning() + } + + uiView.setTorchActive(isOn: torchActive) + } + + public func makeCoordinator() -> Coordinator { + Coordinator( + isScanning: $isScanning, + torchActive: $torchActive, + onSuccess: onSuccess, + onFailure: onFailure, + onTorchActiveChange: onTorchActiveChange + ) + } + + // MARK: - Coordinator + public class Coordinator: NSObject, QRScannerViewDelegate { + @Binding private var isScanning: Bool + @Binding private var torchActive: Bool + private let onSuccess: (String) -> Void + private let onFailure: (QRScannerError) -> Void + private let onTorchActiveChange: ((Bool) -> Void)? + + weak var qrScannerView: QRScannerView? + + init( + isScanning: Binding, + torchActive: Binding, + onSuccess: @escaping (String) -> Void, + onFailure: @escaping (QRScannerError) -> Void, + onTorchActiveChange: ((Bool) -> Void)? + ) { + self._isScanning = isScanning + self._torchActive = torchActive + self.onSuccess = onSuccess + self.onFailure = onFailure + self.onTorchActiveChange = onTorchActiveChange + } + + public func qrScannerView(_ qrScannerView: QRScannerView, didSuccess code: String) { + Task { @MainActor in + self.isScanning = false + } + onSuccess(code) + } + + public func qrScannerView(_ qrScannerView: QRScannerView, didFailure error: QRScannerError) { + onFailure(error) + } + + public func qrScannerView(_ qrScannerView: QRScannerView, didChangeTorchActive isOn: Bool) { + Task { @MainActor in + self.torchActive = isOn + } + onTorchActiveChange?(isOn) + } + } +} diff --git a/QRScannerSample/QRScannerSample.xcodeproj/project.pbxproj b/QRScannerSample/QRScannerSample.xcodeproj/project.pbxproj index 35c2227..9b08a7e 100644 --- a/QRScannerSample/QRScannerSample.xcodeproj/project.pbxproj +++ b/QRScannerSample/QRScannerSample.xcodeproj/project.pbxproj @@ -237,7 +237,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -292,7 +292,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.pbxproj b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.pbxproj new file mode 100644 index 0000000..87160f9 --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.pbxproj @@ -0,0 +1,349 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 16A163F4235710050032684C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 16A163F3235710050032684C /* Assets.xcassets */; }; + 16A163F7235710050032684C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 16A163F5235710050032684C /* LaunchScreen.storyboard */; }; + 16A163FF235710580032684C /* QRScanner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16A163FE235710580032684C /* QRScanner.framework */; }; + 16A16400235710580032684C /* QRScanner.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 16A163FE235710580032684C /* QRScanner.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 16A164A2235710580032684C /* QRScannerSwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A164A0235710580032684C /* QRScannerSwiftUIApp.swift */; }; + 16A164A3235710580032684C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A164A1235710580032684C /* ContentView.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 16A16401235710580032684C /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 16A16400235710580032684C /* QRScanner.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 16A163E9235710040032684C /* QRScannerSwiftUISample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = QRScannerSwiftUISample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 16A163F3235710050032684C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 16A163F6235710050032684C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 16A163F8235710050032684C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 16A163FE235710580032684C /* QRScanner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = QRScanner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 16A164A0235710580032684C /* QRScannerSwiftUIApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRScannerSwiftUIApp.swift; sourceTree = ""; }; + 16A164A1235710580032684C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 16A163E6235710040032684C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 16A163FF235710580032684C /* QRScanner.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 16A163E0235710040032684C = { + isa = PBXGroup; + children = ( + 16A163FE235710580032684C /* QRScanner.framework */, + 16A163EB235710040032684C /* QRScannerSwiftUISample */, + 16A163EA235710040032684C /* Products */, + ); + sourceTree = ""; + }; + 16A163EA235710040032684C /* Products */ = { + isa = PBXGroup; + children = ( + 16A163E9235710040032684C /* QRScannerSwiftUISample.app */, + ); + name = Products; + sourceTree = ""; + }; + 16A163EB235710040032684C /* QRScannerSwiftUISample */ = { + isa = PBXGroup; + children = ( + 16A164A0235710580032684C /* QRScannerSwiftUIApp.swift */, + 16A164A1235710580032684C /* ContentView.swift */, + 16A163F3235710050032684C /* Assets.xcassets */, + 16A163F5235710050032684C /* LaunchScreen.storyboard */, + 16A163F8235710050032684C /* Info.plist */, + ); + path = QRScannerSwiftUISample; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 16A163E8235710040032684C /* QRScannerSwiftUISample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 16A163FB235710050032684C /* Build configuration list for PBXNativeTarget "QRScannerSwiftUISample" */; + buildPhases = ( + 16A163E5235710040032684C /* Sources */, + 16A163E6235710040032684C /* Frameworks */, + 16A163E7235710040032684C /* Resources */, + 16A16401235710580032684C /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = QRScannerSwiftUISample; + productName = QRScannerSwiftUISample; + productReference = 16A163E9235710040032684C /* QRScannerSwiftUISample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 16A163E1235710040032684C /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1030; + LastUpgradeCheck = 1030; + ORGANIZATIONNAME = mercari.com; + TargetAttributes = { + 16A163E8235710040032684C = { + CreatedOnToolsVersion = 10.3; + }; + }; + }; + buildConfigurationList = 16A163E4235710040032684C /* Build configuration list for PBXProject "QRScannerSwiftUISample" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 16A163E0235710040032684C; + productRefGroup = 16A163EA235710040032684C /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 16A163E8235710040032684C /* QRScannerSwiftUISample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 16A163E7235710040032684C /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 16A163F7235710050032684C /* LaunchScreen.storyboard in Resources */, + 16A163F4235710050032684C /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 16A163E5235710040032684C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 16A164A2235710580032684C /* QRScannerSwiftUIApp.swift in Sources */, + 16A164A3235710580032684C /* ContentView.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 16A163F5235710050032684C /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 16A163F6235710050032684C /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 16A163F9235710050032684C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 16A163FA235710050032684C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 16A163FC235710050032684C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = K69VE4UMZN; + INFOPLIST_FILE = QRScannerSwiftUISample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.mercari.QRScannerSwiftUISample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 16A163FD235710050032684C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = K69VE4UMZN; + INFOPLIST_FILE = QRScannerSwiftUISample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.mercari.QRScannerSwiftUISample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 16A163E4235710040032684C /* Build configuration list for PBXProject "QRScannerSwiftUISample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 16A163F9235710050032684C /* Debug */, + 16A163FA235710050032684C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 16A163FB235710050032684C /* Build configuration list for PBXNativeTarget "QRScannerSwiftUISample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 16A163FC235710050032684C /* Debug */, + 16A163FD235710050032684C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 16A163E1235710040032684C /* Project object */; +} diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..2cf3fba --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/xcshareddata/xcschemes/QRScannerSwiftUISample.xcscheme b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/xcshareddata/xcschemes/QRScannerSwiftUISample.xcscheme new file mode 100644 index 0000000..8b42d46 --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample.xcodeproj/xcshareddata/xcschemes/QRScannerSwiftUISample.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/AppIcon.appiconset/Contents.json b/QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/Contents.json b/QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample/Base.lproj/LaunchScreen.storyboard b/QRScannerSwiftUISample/QRScannerSwiftUISample/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..dc2947b --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample/ContentView.swift b/QRScannerSwiftUISample/QRScannerSwiftUISample/ContentView.swift new file mode 100644 index 0000000..00200e4 --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample/ContentView.swift @@ -0,0 +1,77 @@ +import SwiftUI +import QRScanner +import AVFoundation + +struct ContentView: View { + @State private var isScanning = true + @State private var isTorchOn = false + + var body: some View { + ZStack { + QRScannerSwiftUIView( + configuration: .init(isBlurEffectEnabled: true), + isScanning: $isScanning, + torchActive: $isTorchOn, + onSuccess: { qrCode in + print("QR Code scanned: \(qrCode)") + }, + onFailure: { error in + print("QR Scanner error: \(error.localizedDescription)") + }, + onTorchActiveChange: { isOn in + isTorchOn = isOn + } + ) + .edgesIgnoringSafeArea(.all) + .onAppear { + setupQRScanner() + } + .onDisappear { + isScanning = false + } + + VStack { + Spacer() + HStack { + Spacer() + + Button(action: { + isTorchOn.toggle() + }) { + Image(systemName: isTorchOn ? "flashlight.on.fill" : "flashlight.off.fill") + .font(.title2) + .foregroundColor(.white) + .frame(width: 44, height: 44) + .background(Color.black.opacity(0.6)) + .clipShape(Circle()) + } + .padding(.trailing, 20) + .padding(.bottom, 50) + } + } + } + } + + private func setupQRScanner() { + switch AVCaptureDevice.authorizationStatus(for: .video) { + case .authorized: + isScanning = true + case .notDetermined: + AVCaptureDevice.requestAccess(for: .video) { granted in + DispatchQueue.main.async { + if granted { + isScanning = true + } else { + print("Camera is required to use in this application") + } + } + } + default: + print("Camera access denied or restricted") + } + } +} + +#Preview { + ContentView() +} diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample/Info.plist b/QRScannerSwiftUISample/QRScannerSwiftUISample/Info.plist new file mode 100644 index 0000000..378668a --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample/Info.plist @@ -0,0 +1,43 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + NSCameraUsageDescription + Camera is required to use this application + + diff --git a/QRScannerSwiftUISample/QRScannerSwiftUISample/QRScannerSwiftUIApp.swift b/QRScannerSwiftUISample/QRScannerSwiftUISample/QRScannerSwiftUIApp.swift new file mode 100644 index 0000000..00863b9 --- /dev/null +++ b/QRScannerSwiftUISample/QRScannerSwiftUISample/QRScannerSwiftUIApp.swift @@ -0,0 +1,10 @@ +import SwiftUI + +@main +struct QRScannerSwiftUIApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} \ No newline at end of file diff --git a/SwiftUI_Usage.md b/SwiftUI_Usage.md new file mode 100644 index 0000000..0359443 --- /dev/null +++ b/SwiftUI_Usage.md @@ -0,0 +1,151 @@ +# QRScanner SwiftUI Usage Guide + +## Overview + +QRScanner now supports SwiftUI through the `QRScannerSwiftUIView` wrapper, making it easy to integrate into SwiftUI applications. + +## Basic Usage + +### 1. Import Libraries + +```swift +import SwiftUI +import QRScanner +import AVFoundation +``` + +### 2. Simple Usage + +```swift +struct ContentView: View { + @State private var scannedCode = "" + @State private var isPresented = false + + var body: some View { + VStack { + Button("Start Scanning") { + isPresented = true + } + + if !scannedCode.isEmpty { + Text("Scanned: \(scannedCode)") + } + } + .sheet(isPresented: $isPresented) { + QRScannerSwiftUIView( + onSuccess: { code in + scannedCode = code + isPresented = false + }, + onFailure: { error in + print("Scan error: \(error)") + isPresented = false + } + ) + } + } +} +``` + +### 3. Advanced Usage - With Controls + +```swift +struct AdvancedQRScannerView: View { + @State private var scannedCode = "" + @State private var isScanning = true + @State private var torchActive = false + @State private var errorMessage = "" + + var body: some View { + VStack { + QRScannerSwiftUIView( + configuration: .init( + focusImagePadding: 12.0, + animationDuration: 0.3, + isBlurEffectEnabled: true + ), + isScanning: $isScanning, + torchActive: $torchActive, + onSuccess: { code in + scannedCode = code + isScanning = false + }, + onFailure: { error in + errorMessage = error.localizedDescription + } + ) + + HStack { + Button(isScanning ? "Pause" : "Resume") { + isScanning.toggle() + } + + Button("Torch") { + torchActive.toggle() + } + } + .padding() + } + } +} +``` + +## Configuration Options + +### Configuration Parameters + +- `focusImage`: Custom focus frame image +- `focusImagePadding`: Focus frame padding (default: 8.0) +- `animationDuration`: Animation duration (default: 0.5) +- `isBlurEffectEnabled`: Enable blur effect (default: false) + +### Binding Parameters + +- `isScanning`: Control scanning state +- `torchActive`: Control torch state + +### Callback Functions + +- `onSuccess`: Scan success callback +- `onFailure`: Scan failure callback +- `onTorchActiveChange`: Torch state change callback + +## Permission Handling + +Camera permission is required before use: + +```swift +private func requestCameraPermission() { + switch AVCaptureDevice.authorizationStatus(for: .video) { + case .authorized: + // Authorized, can start scanning + break + case .notDetermined: + AVCaptureDevice.requestAccess(for: .video) { granted in + DispatchQueue.main.async { + if granted { + // Permission granted + } else { + // Permission denied + } + } + } + case .denied, .restricted: + // Show settings alert + break + @unknown default: + break + } +} +``` + +## Important Notes + +1. Ensure camera usage description is added to Info.plist +2. QRScannerSwiftUIView requires iOS 13.0+ +3. Scanning automatically stops after success, can restart via isScanning +4. Recommended to stop scanning when view disappears to save battery + +## Sample Project + +For complete example code, refer to the `QRScannerSwiftUISample` directory. \ No newline at end of file From f110d8bc25e831262f64925a371f3ec37b8f559c Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 17:39:16 +0900 Subject: [PATCH 02/10] update ci.yml --- .github/workflows/ci.yml | 57 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51ebfc7..4db7141 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,14 +12,63 @@ jobs: runs-on: macOS-latest strategy: matrix: - destination: ['platform=iOS Simulator,OS=16.1,name=iPhone 14 Pro Max'] - xcode: ['/Applications/Xcode_14.1.app/Contents/Developer'] + destination: ['platform=iOS Simulator,OS=18.0,name=iPhone 16 Pro Max'] + xcode: ['/Applications/Xcode_16.4.app/Contents/Developer'] steps: - name: Checkout - uses: actions/checkout@v1 - - name: Run test + uses: actions/checkout@v4 + - name: Run unit tests run: xcodebuild test -workspace QRScanner.xcworkspace -scheme UnitTests -destination "${destination}" env: destination: ${{ matrix.destination }} DEVELOPER_DIR: ${{ matrix.xcode }} + + build-samples: + name: Build Sample Apps + runs-on: macOS-latest + strategy: + matrix: + destination: ['platform=iOS Simulator,OS=18.0,name=iPhone 16 Pro Max'] + xcode: ['/Applications/Xcode_16.4.app/Contents/Developer'] + scheme: ['QRScannerSample', 'QRScannerSwiftUISample'] + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build ${{ matrix.scheme }} + run: xcodebuild build -workspace QRScanner.xcworkspace -scheme "${{ matrix.scheme }}" -destination "${destination}" + env: + destination: ${{ matrix.destination }} + DEVELOPER_DIR: ${{ matrix.xcode }} + + swift-package-manager: + name: Swift Package Manager + runs-on: macOS-latest + strategy: + matrix: + xcode: ['/Applications/Xcode_16.4.app/Contents/Developer'] + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build with SPM + run: swift build + env: + DEVELOPER_DIR: ${{ matrix.xcode }} + + cocoapods: + name: CocoaPods Lint + runs-on: macOS-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0 + - name: Install CocoaPods + run: gem install cocoapods + - name: Lint podspec + run: pod lib lint --allow-warnings From ecfc5d56464b29bcd1d22964cda40eec44bb4a13 Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 17:44:19 +0900 Subject: [PATCH 03/10] update ci.yml --- .github/workflows/ci.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4db7141..0b4ba1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,16 +13,16 @@ jobs: strategy: matrix: destination: ['platform=iOS Simulator,OS=18.0,name=iPhone 16 Pro Max'] - xcode: ['/Applications/Xcode_16.4.app/Contents/Developer'] steps: - name: Checkout uses: actions/checkout@v4 + - name: Select latest Xcode + run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - name: Run unit tests run: xcodebuild test -workspace QRScanner.xcworkspace -scheme UnitTests -destination "${destination}" env: destination: ${{ matrix.destination }} - DEVELOPER_DIR: ${{ matrix.xcode }} build-samples: name: Build Sample Apps @@ -30,32 +30,29 @@ jobs: strategy: matrix: destination: ['platform=iOS Simulator,OS=18.0,name=iPhone 16 Pro Max'] - xcode: ['/Applications/Xcode_16.4.app/Contents/Developer'] scheme: ['QRScannerSample', 'QRScannerSwiftUISample'] steps: - name: Checkout uses: actions/checkout@v4 + - name: Select latest Xcode + run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - name: Build ${{ matrix.scheme }} run: xcodebuild build -workspace QRScanner.xcworkspace -scheme "${{ matrix.scheme }}" -destination "${destination}" env: destination: ${{ matrix.destination }} - DEVELOPER_DIR: ${{ matrix.xcode }} swift-package-manager: name: Swift Package Manager runs-on: macOS-latest - strategy: - matrix: - xcode: ['/Applications/Xcode_16.4.app/Contents/Developer'] steps: - name: Checkout uses: actions/checkout@v4 + - name: Select latest Xcode + run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - name: Build with SPM run: swift build - env: - DEVELOPER_DIR: ${{ matrix.xcode }} cocoapods: name: CocoaPods Lint From 0712142da00bf864087e41d792612381cfebf853 Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 17:47:26 +0900 Subject: [PATCH 04/10] update ci.yml --- .github/workflows/ci.yml | 45 ---------------------------------------- 1 file changed, 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b4ba1b..9474374 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,48 +24,3 @@ jobs: env: destination: ${{ matrix.destination }} - build-samples: - name: Build Sample Apps - runs-on: macOS-latest - strategy: - matrix: - destination: ['platform=iOS Simulator,OS=18.0,name=iPhone 16 Pro Max'] - scheme: ['QRScannerSample', 'QRScannerSwiftUISample'] - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Select latest Xcode - run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - - name: Build ${{ matrix.scheme }} - run: xcodebuild build -workspace QRScanner.xcworkspace -scheme "${{ matrix.scheme }}" -destination "${destination}" - env: - destination: ${{ matrix.destination }} - - swift-package-manager: - name: Swift Package Manager - runs-on: macOS-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Select latest Xcode - run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - - name: Build with SPM - run: swift build - - cocoapods: - name: CocoaPods Lint - runs-on: macOS-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.0 - - name: Install CocoaPods - run: gem install cocoapods - - name: Lint podspec - run: pod lib lint --allow-warnings From 008a622b1771d308f8d4d0f906f26ed695343579 Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 17:52:51 +0900 Subject: [PATCH 05/10] update ci.yml --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9474374..889907f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,6 @@ jobs: - name: Select latest Xcode run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - name: Run unit tests - run: xcodebuild test -workspace QRScanner.xcworkspace -scheme UnitTests -destination "${destination}" + run: xcodebuild test -workspace QRScanner.xcworkspace -scheme UnitTests -destination "${destination}" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO env: destination: ${{ matrix.destination }} - From 599c7cac35bfaa4c3a2c1605432749ff1edcc33c Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 18:02:28 +0900 Subject: [PATCH 06/10] update README.md --- README.md | 161 +++++++++++++++++++++++++++++++++++------------ SwiftUI_Usage.md | 151 -------------------------------------------- 2 files changed, 120 insertions(+), 192 deletions(-) delete mode 100644 SwiftUI_Usage.md diff --git a/README.md b/README.md index 1bb4dec..1a74756 100644 --- a/README.md +++ b/README.md @@ -11,71 +11,50 @@ A simple QR Code scanner framework for iOS. Provides a similar scan effect to io ## Feature - Similar to iOS 13.0+ design -- Simple usage Sample -- Support from iOS 10.0+ +- Simple usage UIKit Sample | SwiftUI Sample +- Support SwiftUI (iOS 14.0+) +- Support from iOS 14.0+ ## Development Requirements -- iOS 11.0+ +- iOS 14.0+ - Swift: 5.7.1 -- Xcode Version: 14.1 +- Xcode Version: 16.0+ ## Installation -QRScanner supports multiple methods for installing the library in a project. -### Installation with CocoaPods - -- To integrate QRScanner into your Xcode project using CocoaPods, specify it in your Podfile -```ruby - platform :ios, '11.0' - pod 'MercariQRScanner' -``` - -- Run command -``` - pod install -``` -- Write Import statement on your source file -```swift - import MercariQRScanner -``` - -### Installation with Swift Package Manager +### Swift Package Manager Once you have your Swift package set up, adding QRScanner as a dependency is as easy as adding it to the dependencies value of your Package.swift. -``` +```swift dependencies: [ .package(url: "https://github.com/mercari/QRScanner.git", .upToNextMajor(from: "1.9.0")) ] ``` -- Write Import statement on your source file -```swift -import QRScanner -``` +Or add it through Xcode: +1. Go to **File** → **Add Package Dependencies** +2. Enter the repository URL: `https://github.com/mercari/QRScanner.git` +3. Select the version range and add to your target -### Installation with Carthage - -- To integrate QRScanner, add the following to your Cartfile. -``` -github "mercari/QRScanner" -``` -- Write Import statement on your source file +Write Import statement on your source file: ```swift import QRScanner ``` ## Usage -See [QRScannerSample](https://github.com/mercari/QRScanner/tree/master/QRScannerSample) +See [QRScannerSample](https://github.com/mercari/QRScanner/tree/master/QRScannerSample) for UIKit usage or [QRScannerSwiftUISample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample) for SwiftUI usage. ### Add `Privacy - Camera Usage Description` to Info.plist file -### The Basis Of Usage +## UIKit Usage + +### Basic UIKit Implementation ```swift -import QRScanner // If use the Pod way, please import MercariQRScanner +import QRScanner import AVFoundation final class ViewController: UIViewController { @@ -128,7 +107,7 @@ extension ViewController: QRScannerViewDelegate { } ``` -### Customization +### UIKit Customization #### Source Code Way @@ -155,7 +134,7 @@ override func viewDidLoad() { |-|-| ||| -### Add FlashButton +### UIKit Add FlashButton [FlashButtonSample](https://github.com/mercari/QRScanner/blob/master/QRScannerSample/QRScannerSample/FlashButton.swift) @@ -181,7 +160,7 @@ extension ViewController: QRScannerViewDelegate { } ``` -### Add Blur Effect +### UIKit Add Blur Effect #### Source Code Way @@ -195,6 +174,106 @@ extension ViewController: QRScannerViewDelegate { |-| || +## SwiftUI Usage + +### Basic SwiftUI Implementation + +```swift +import SwiftUI +import QRScanner +import AVFoundation + +struct ContentView: View { + @State private var scannedCode = "" + @State private var isPresented = false + + var body: some View { + VStack { + Button("Start Scanning") { + isPresented = true + } + + if !scannedCode.isEmpty { + Text("Scanned: \(scannedCode)") + } + } + .sheet(isPresented: $isPresented) { + QRScannerSwiftUIView( + onSuccess: { code in + scannedCode = code + isPresented = false + }, + onFailure: { error in + print("Scan error: \(error)") + isPresented = false + } + ) + } + } +} +``` + +### Advanced SwiftUI Usage with Controls + +```swift +struct AdvancedQRScannerView: View { + @State private var scannedCode = "" + @State private var isScanning = true + @State private var torchActive = false + + var body: some View { + VStack { + QRScannerSwiftUIView( + configuration: .init( + focusImagePadding: 12.0, + animationDuration: 0.3, + isBlurEffectEnabled: true + ), + isScanning: $isScanning, + torchActive: $torchActive, + onSuccess: { code in + scannedCode = code + isScanning = false + }, + onFailure: { error in + print("Error: \(error.localizedDescription)") + } + ) + + HStack { + Button(isScanning ? "Pause" : "Resume") { + isScanning.toggle() + } + + Button("Torch") { + torchActive.toggle() + } + } + .padding() + } + } +} +``` + +### SwiftUI Configuration Options + +#### Configuration Parameters +- `focusImage`: Custom focus frame image +- `focusImagePadding`: Focus frame padding (default: 8.0) +- `animationDuration`: Animation duration (default: 0.5) +- `isBlurEffectEnabled`: Enable blur effect (default: false) + +#### Binding Parameters +- `isScanning`: Control scanning state +- `torchActive`: Control torch state + +#### Callback Functions +- `onSuccess`: Scan success callback +- `onFailure`: Scan failure callback +- `onTorchActiveChange`: Torch state change callback + +For a complete SwiftUI example, see [QRScannerSwiftUISample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample). + ## Committers * Hitsu ([@hitsubunnu](https://github.com/hitsubunnu)) diff --git a/SwiftUI_Usage.md b/SwiftUI_Usage.md deleted file mode 100644 index 0359443..0000000 --- a/SwiftUI_Usage.md +++ /dev/null @@ -1,151 +0,0 @@ -# QRScanner SwiftUI Usage Guide - -## Overview - -QRScanner now supports SwiftUI through the `QRScannerSwiftUIView` wrapper, making it easy to integrate into SwiftUI applications. - -## Basic Usage - -### 1. Import Libraries - -```swift -import SwiftUI -import QRScanner -import AVFoundation -``` - -### 2. Simple Usage - -```swift -struct ContentView: View { - @State private var scannedCode = "" - @State private var isPresented = false - - var body: some View { - VStack { - Button("Start Scanning") { - isPresented = true - } - - if !scannedCode.isEmpty { - Text("Scanned: \(scannedCode)") - } - } - .sheet(isPresented: $isPresented) { - QRScannerSwiftUIView( - onSuccess: { code in - scannedCode = code - isPresented = false - }, - onFailure: { error in - print("Scan error: \(error)") - isPresented = false - } - ) - } - } -} -``` - -### 3. Advanced Usage - With Controls - -```swift -struct AdvancedQRScannerView: View { - @State private var scannedCode = "" - @State private var isScanning = true - @State private var torchActive = false - @State private var errorMessage = "" - - var body: some View { - VStack { - QRScannerSwiftUIView( - configuration: .init( - focusImagePadding: 12.0, - animationDuration: 0.3, - isBlurEffectEnabled: true - ), - isScanning: $isScanning, - torchActive: $torchActive, - onSuccess: { code in - scannedCode = code - isScanning = false - }, - onFailure: { error in - errorMessage = error.localizedDescription - } - ) - - HStack { - Button(isScanning ? "Pause" : "Resume") { - isScanning.toggle() - } - - Button("Torch") { - torchActive.toggle() - } - } - .padding() - } - } -} -``` - -## Configuration Options - -### Configuration Parameters - -- `focusImage`: Custom focus frame image -- `focusImagePadding`: Focus frame padding (default: 8.0) -- `animationDuration`: Animation duration (default: 0.5) -- `isBlurEffectEnabled`: Enable blur effect (default: false) - -### Binding Parameters - -- `isScanning`: Control scanning state -- `torchActive`: Control torch state - -### Callback Functions - -- `onSuccess`: Scan success callback -- `onFailure`: Scan failure callback -- `onTorchActiveChange`: Torch state change callback - -## Permission Handling - -Camera permission is required before use: - -```swift -private func requestCameraPermission() { - switch AVCaptureDevice.authorizationStatus(for: .video) { - case .authorized: - // Authorized, can start scanning - break - case .notDetermined: - AVCaptureDevice.requestAccess(for: .video) { granted in - DispatchQueue.main.async { - if granted { - // Permission granted - } else { - // Permission denied - } - } - } - case .denied, .restricted: - // Show settings alert - break - @unknown default: - break - } -} -``` - -## Important Notes - -1. Ensure camera usage description is added to Info.plist -2. QRScannerSwiftUIView requires iOS 13.0+ -3. Scanning automatically stops after success, can restart via isScanning -4. Recommended to stop scanning when view disappears to save battery - -## Sample Project - -For complete example code, refer to the `QRScannerSwiftUISample` directory. \ No newline at end of file From 2d349dea648251c21a86ed0d2c754f0a3e1b50e9 Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 18:06:52 +0900 Subject: [PATCH 07/10] update README.md --- README.md | 200 +++++++++++++++++++++++++++--------------------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index 1a74756..1314eff 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,106 @@ See [QRScannerSample](https://github.com/mercari/QRScanner/tree/master/QRScanner +## SwiftUI Usage + +### Basic SwiftUI Implementation + +```swift +import SwiftUI +import QRScanner +import AVFoundation + +struct ContentView: View { + @State private var scannedCode = "" + @State private var isPresented = false + + var body: some View { + VStack { + Button("Start Scanning") { + isPresented = true + } + + if !scannedCode.isEmpty { + Text("Scanned: \(scannedCode)") + } + } + .sheet(isPresented: $isPresented) { + QRScannerSwiftUIView( + onSuccess: { code in + scannedCode = code + isPresented = false + }, + onFailure: { error in + print("Scan error: \(error)") + isPresented = false + } + ) + } + } +} +``` + +### Advanced SwiftUI Usage with Controls + +```swift +struct AdvancedQRScannerView: View { + @State private var scannedCode = "" + @State private var isScanning = true + @State private var torchActive = false + + var body: some View { + VStack { + QRScannerSwiftUIView( + configuration: .init( + focusImagePadding: 12.0, + animationDuration: 0.3, + isBlurEffectEnabled: true + ), + isScanning: $isScanning, + torchActive: $torchActive, + onSuccess: { code in + scannedCode = code + isScanning = false + }, + onFailure: { error in + print("Error: \(error.localizedDescription)") + } + ) + + HStack { + Button(isScanning ? "Pause" : "Resume") { + isScanning.toggle() + } + + Button("Torch") { + torchActive.toggle() + } + } + .padding() + } + } +} +``` + +### SwiftUI Configuration Options + +#### Configuration Parameters +- `focusImage`: Custom focus frame image +- `focusImagePadding`: Focus frame padding (default: 8.0) +- `animationDuration`: Animation duration (default: 0.5) +- `isBlurEffectEnabled`: Enable blur effect (default: false) + +#### Binding Parameters +- `isScanning`: Control scanning state +- `torchActive`: Control torch state + +#### Callback Functions +- `onSuccess`: Scan success callback +- `onFailure`: Scan failure callback +- `onTorchActiveChange`: Torch state change callback + +For a complete SwiftUI example, see [QRScannerSwiftUISample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample). + ## UIKit Usage ### Basic UIKit Implementation @@ -174,106 +274,6 @@ extension ViewController: QRScannerViewDelegate { |-| || -## SwiftUI Usage - -### Basic SwiftUI Implementation - -```swift -import SwiftUI -import QRScanner -import AVFoundation - -struct ContentView: View { - @State private var scannedCode = "" - @State private var isPresented = false - - var body: some View { - VStack { - Button("Start Scanning") { - isPresented = true - } - - if !scannedCode.isEmpty { - Text("Scanned: \(scannedCode)") - } - } - .sheet(isPresented: $isPresented) { - QRScannerSwiftUIView( - onSuccess: { code in - scannedCode = code - isPresented = false - }, - onFailure: { error in - print("Scan error: \(error)") - isPresented = false - } - ) - } - } -} -``` - -### Advanced SwiftUI Usage with Controls - -```swift -struct AdvancedQRScannerView: View { - @State private var scannedCode = "" - @State private var isScanning = true - @State private var torchActive = false - - var body: some View { - VStack { - QRScannerSwiftUIView( - configuration: .init( - focusImagePadding: 12.0, - animationDuration: 0.3, - isBlurEffectEnabled: true - ), - isScanning: $isScanning, - torchActive: $torchActive, - onSuccess: { code in - scannedCode = code - isScanning = false - }, - onFailure: { error in - print("Error: \(error.localizedDescription)") - } - ) - - HStack { - Button(isScanning ? "Pause" : "Resume") { - isScanning.toggle() - } - - Button("Torch") { - torchActive.toggle() - } - } - .padding() - } - } -} -``` - -### SwiftUI Configuration Options - -#### Configuration Parameters -- `focusImage`: Custom focus frame image -- `focusImagePadding`: Focus frame padding (default: 8.0) -- `animationDuration`: Animation duration (default: 0.5) -- `isBlurEffectEnabled`: Enable blur effect (default: false) - -#### Binding Parameters -- `isScanning`: Control scanning state -- `torchActive`: Control torch state - -#### Callback Functions -- `onSuccess`: Scan success callback -- `onFailure`: Scan failure callback -- `onTorchActiveChange`: Torch state change callback - -For a complete SwiftUI example, see [QRScannerSwiftUISample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample). - ## Committers * Hitsu ([@hitsubunnu](https://github.com/hitsubunnu)) From efaf7c699037972c5cf903922b382f969f678027 Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 18:14:31 +0900 Subject: [PATCH 08/10] update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1314eff..4a24b72 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ # QRScanner -A simple QR Code scanner framework for iOS. Provides a similar scan effect to ios13+. Written in Swift. +A modern QR Code scanner framework for iOS with comprehensive SwiftUI and UIKit support. Delivers a native iOS scanning experience with advanced customization options. Written in Swift. * [日本語のブログ](https://tech.mercari.com/entry/2019/12/12/094129) -|iOS 13.0+| Use QRScanner in iOS 10.0+| +|iPhone native camera|QRScanner implementation| |-|-| ||| "QR Code" is a registered trademark of DENSO WAVE INCORPORATED ## Feature -- Similar to iOS 13.0+ design +- Similar to iPhone native camera design - Simple usage UIKit Sample | SwiftUI Sample - Support SwiftUI (iOS 14.0+) - Support from iOS 14.0+ ## Development Requirements - iOS 14.0+ -- Swift: 5.7.1 +- Swift: 5.9 - Xcode Version: 16.0+ ## Installation From 7d898d278de978e4e99abb23c6eeb1d57acbec2a Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 18:16:44 +0900 Subject: [PATCH 09/10] update README.md --- README.md | 117 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 4a24b72..6c64ab5 100644 --- a/README.md +++ b/README.md @@ -9,49 +9,67 @@ A modern QR Code scanner framework for iOS with comprehensive SwiftUI and UIKit "QR Code" is a registered trademark of DENSO WAVE INCORPORATED -## Feature -- Similar to iPhone native camera design -- Simple usage UIKit Sample | SwiftUI Sample -- Support SwiftUI (iOS 14.0+) -- Support from iOS 14.0+ +## Features -## Development Requirements -- iOS 14.0+ -- Swift: 5.9 -- Xcode Version: 16.0+ +- 🎯 **Native iOS Design** - Matches iPhone's built-in camera scanning experience +- 🚀 **SwiftUI & UIKit Support** - Full compatibility with both modern and traditional iOS development +- 📱 **iOS 14.0+** - Built for modern iOS with latest Swift features +- ⚡ **Easy Integration** - Simple setup with comprehensive examples +- 🎨 **Highly Customizable** - Extensive configuration options for focus frame, animations, and effects +- 💡 **Production Ready** - Battle-tested in Mercari's production apps + +**Quick Start:** [SwiftUI Example](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample) | [UIKit Example](https://github.com/mercari/QRScanner/tree/master/QRScannerSample) + +## Requirements + +- **iOS:** 14.0+ +- **Swift:** 5.9+ +- **Xcode:** 16.0+ ## Installation -### Swift Package Manager +### Swift Package Manager (Recommended) + +#### Via Xcode (Easiest) +1. **File** → **Add Package Dependencies** +2. Enter: `https://github.com/mercari/QRScanner.git` +3. Select version and add to your target -Once you have your Swift package set up, adding QRScanner as a dependency is as easy as adding it to the dependencies value of your Package.swift. +#### Via Package.swift ```swift dependencies: [ .package(url: "https://github.com/mercari/QRScanner.git", .upToNextMajor(from: "1.9.0")) ] ``` -Or add it through Xcode: -1. Go to **File** → **Add Package Dependencies** -2. Enter the repository URL: `https://github.com/mercari/QRScanner.git` -3. Select the version range and add to your target - -Write Import statement on your source file: +#### Import ```swift import QRScanner ``` -## Usage +## Quick Setup -See [QRScannerSample](https://github.com/mercari/QRScanner/tree/master/QRScannerSample) for UIKit usage or [QRScannerSwiftUISample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample) for SwiftUI usage. +### 1. Camera Permission +Add camera usage description to your `Info.plist`: -### Add `Privacy - Camera Usage Description` to Info.plist file +```xml +NSCameraUsageDescription +Camera access is required for QR code scanning +``` +### 2. Choose Your Framework +- **SwiftUI**: Modern declarative UI (recommended for new projects) +- **UIKit**: Traditional imperative UI (for existing projects) + +Complete examples: [SwiftUI Sample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample) | [UIKit Sample](https://github.com/mercari/QRScanner/tree/master/QRScannerSample) + ## SwiftUI Usage -### Basic SwiftUI Implementation +> 💡 **Recommended for new projects** - SwiftUI provides a more modern and concise API + +### Basic Implementation ```swift import SwiftUI @@ -88,7 +106,7 @@ struct ContentView: View { } ``` -### Advanced SwiftUI Usage with Controls +### Advanced Implementation ```swift struct AdvancedQRScannerView: View { @@ -130,28 +148,33 @@ struct AdvancedQRScannerView: View { } ``` -### SwiftUI Configuration Options +### Configuration Options -#### Configuration Parameters -- `focusImage`: Custom focus frame image -- `focusImagePadding`: Focus frame padding (default: 8.0) -- `animationDuration`: Animation duration (default: 0.5) -- `isBlurEffectEnabled`: Enable blur effect (default: false) +| Parameter | Type | Default | Description | +|-----------|------|---------|-------------| +| `focusImage` | `UIImage?` | `nil` | Custom focus frame image | +| `focusImagePadding` | `CGFloat` | `8.0` | Focus frame padding | +| `animationDuration` | `Double` | `0.5` | Animation duration | +| `isBlurEffectEnabled` | `Bool` | `false` | Enable blur effect | -#### Binding Parameters -- `isScanning`: Control scanning state -- `torchActive`: Control torch state +| Binding | Type | Description | +|---------|------|-------------| +| `isScanning` | `Bool` | Control scanning state | +| `torchActive` | `Bool` | Control torch state | -#### Callback Functions -- `onSuccess`: Scan success callback -- `onFailure`: Scan failure callback -- `onTorchActiveChange`: Torch state change callback +| Callback | Description | +|----------|-------------| +| `onSuccess` | Called when QR code is successfully scanned | +| `onFailure` | Called when scanning fails | +| `onTorchActiveChange` | Called when torch state changes | -For a complete SwiftUI example, see [QRScannerSwiftUISample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample). +📘 **Complete Example:** [QRScannerSwiftUISample](https://github.com/mercari/QRScanner/tree/master/QRScannerSwiftUISample) ## UIKit Usage -### Basic UIKit Implementation +> 🔧 **For existing projects** - UIKit integration with full customization support + +### Basic Implementation ```swift import QRScanner @@ -207,9 +230,7 @@ extension ViewController: QRScannerViewDelegate { } ``` -### UIKit Customization - -#### Source Code Way +### Customization ```swift override func viewDidLoad() { @@ -234,9 +255,9 @@ override func viewDidLoad() { |-|-| ||| -### UIKit Add FlashButton +### Adding Flash Control -[FlashButtonSample](https://github.com/mercari/QRScanner/blob/master/QRScannerSample/QRScannerSample/FlashButton.swift) +Example: [FlashButton.swift](https://github.com/mercari/QRScanner/blob/master/QRScannerSample/QRScannerSample/FlashButton.swift) ```swift final class ViewController: UIViewController { @@ -260,19 +281,13 @@ extension ViewController: QRScannerViewDelegate { } ``` -### UIKit Add Blur Effect - -#### Source Code Way +### Adding Blur Effect ```swift - qrScannerView.configure(delegate: self, input: .init(isBlurEffectEnabled: true)) +qrScannerView.configure(delegate: self, input: .init(isBlurEffectEnabled: true)) ``` -#### Interface Builder Way - -|Customize| -|-| -|| +📘 **Complete Example:** [QRScannerSample](https://github.com/mercari/QRScanner/tree/master/QRScannerSample) ## Committers From bd0a64415ebd3a849016acd0213a8810c3aafddc Mon Sep 17 00:00:00 2001 From: Hitsu Bunu Date: Fri, 4 Jul 2025 19:59:11 +0900 Subject: [PATCH 10/10] fix bug --- QRScanner/QRScannerSwiftUIView.swift | 5 +++-- QRScanner/QRScannerView.swift | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/QRScanner/QRScannerSwiftUIView.swift b/QRScanner/QRScannerSwiftUIView.swift index b0d32a3..f5f7f87 100644 --- a/QRScanner/QRScannerSwiftUIView.swift +++ b/QRScanner/QRScannerSwiftUIView.swift @@ -59,11 +59,11 @@ public struct QRScannerSwiftUIView: UIViewRepresentable { ) qrScannerView.configure(delegate: context.coordinator, input: input) context.coordinator.qrScannerView = qrScannerView - + if isScanning { qrScannerView.startRunning() } - + return qrScannerView } @@ -130,3 +130,4 @@ public struct QRScannerSwiftUIView: UIViewRepresentable { } } } + diff --git a/QRScanner/QRScannerView.swift b/QRScanner/QRScannerView.swift index 098dce4..2159ab2 100644 --- a/QRScanner/QRScannerView.swift +++ b/QRScanner/QRScannerView.swift @@ -126,6 +126,19 @@ public class QRScannerView: UIView { videoDevice.unlockForConfiguration() } + public override func layoutSubviews() { + super.layoutSubviews() + if previewLayer?.frame != self.bounds { + previewLayer?.frame = self.bounds + blurEffectView.frame = self.bounds + + let width = self.bounds.width * 0.618 + let x = self.bounds.width * 0.191 + let y = self.bounds.height * 0.191 + focusImageView.frame = CGRect(x: x, y: y, width: width, height: width) + } + } + deinit { setTorchActive(isOn: false) focusImageView.removeFromSuperview()