Skip to content
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
11 changes: 4 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@ let package = Package(
name: "SharkCardScan",
platforms: [ .iOS(.v13)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "SharkCardScan",
targets: ["SharkCardScan"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"), dependencies: [
.package(
.package(
name: "SharkUtils",
url: "https://github.com/gymshark/ios-shark-utils.git",
.exact("1.0.5")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "SharkCardScan",
dependencies: ["SharkUtils"]),
dependencies: ["SharkUtils"],
path: "Sources",
resources: [.copy("Resources/PrivacyInfo.xcprivacy")]),
.testTarget(
name: "SharkCardScanTests",
dependencies: ["SharkCardScan"]),
Expand Down
35 changes: 35 additions & 0 deletions Sources/Resources/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeName</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypePaymentInfo</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
</array>
<key>NSPrivacyTracking</key>
<false/>
</dict>
</plist>
12 changes: 8 additions & 4 deletions Sources/SharkCardScan/CardScanViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class CardScanViewModel {
private let cameraAccess: CameraAccessProtocol
private let cameraStream: PixelBufferStream
private let cardReader: CardScannerProtocol
private let dismissHandler: (() -> Void)?
private let noPermissionAction: () -> Void
var didDismiss: (() -> Void)?
private let successHandler: (CardScannerResponse) -> Void
Expand All @@ -51,13 +52,15 @@ public class CardScanViewModel {
}

public init(cameraAccess: CameraAccessProtocol = CameraAccess(),
cameraStream: PixelBufferStream = CameraPixelBufferStream(),
cardReader: CardScannerProtocol = CardScanner(),
noPermissionAction: @escaping () -> Void,
successHandler: @escaping (CardScannerResponse) -> Void) {
cameraStream: PixelBufferStream = CameraPixelBufferStream(),
cardReader: CardScannerProtocol = CardScanner(),
dismissHandler: (() -> Void)? = nil,
noPermissionAction: @escaping () -> Void,
successHandler: @escaping (CardScannerResponse) -> Void) {
self.cameraAccess = cameraAccess
self.cameraStream = cameraStream
self.cardReader = cardReader
self.dismissHandler = dismissHandler
self.noPermissionAction = noPermissionAction
self.successHandler = successHandler
cameraStream.output = cardReader.read(buffer:orientation:)
Expand Down Expand Up @@ -85,6 +88,7 @@ public class CardScanViewModel {

func didTapClose() {
didDismiss?()
dismissHandler?()
}

func startCamera() {
Expand Down
20 changes: 13 additions & 7 deletions Sources/SharkCardScan/PixelBufferStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ public class CameraPixelBufferStream: NSObject, PixelBufferStream, AVCaptureVide
writeSafe.perform {
guard runningBacking != newValue else { return }
runningBacking = newValue
if newValue {
session.startRunning()
} else {
session.stopRunning()
}
manageAVCaptureSession()
}
}
}

public override init() {
let writeSafe = WriteSafe()
self.writeSafe = writeSafe
Expand Down Expand Up @@ -111,7 +107,17 @@ public class CameraPixelBufferStream: NSObject, PixelBufferStream, AVCaptureVide
contentView
]}
}


private func manageAVCaptureSession() {
if runningBacking {
DispatchQueue
.global(qos: .background)
.async { [weak self] in self?.session.startRunning() }
return
}
session.stopRunning()
}

deinit {
running = false
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SharkCardScan/SharkCardScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SharkCardScanViewController: UIViewController {
private var styling: CardScanStyling

private lazy var closeButton = UIButton().with {
$0.setBackgroundImage(UIImage(named: "rounded close"), for: .normal)
$0.setBackgroundImage(UIImage(named: "rounded close", in: Bundle.module, compatibleWith: nil), for: .normal)
$0.accessibilityLabel = String(describing: SharkCardScanViewController.self) + "." + "CloseButton"
}

Expand Down