Skip to content

fix memory leaks #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// swift-tools-version:5.0
// swift-tools-version:5.9
import PackageDescription

let package = Package(
name: "QRCodeReader",
products: [
.library(name: "QRCodeReader", targets: ["QRCodeReader"]),
],
targets: [
.target(
name: "QRCodeReader",
dependencies: [],
path: "Sources"),
]
name: "QRCodeReader",
platforms: [
.iOS(.v16)
],
products: [
.library(name: "QRCodeReader", targets: ["QRCodeReader"])
],
targets: [
.target(
name: "QRCodeReader",
dependencies: [],
)
]
)

2 changes: 1 addition & 1 deletion QRCodeReader.swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '8.0'

s.framework = 'AVFoundation'
s.source_files = 'Sources/*.swift'
s.source_files = 'Sources/QRCodeReader/*.swift'
s.requires_arc = true
end
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat

super.init()

sessionQueue.async {
sessionQueue.async { [weak self] in
guard let self = self else { return }
self.configureDefaultComponents(withCaptureDevicePosition: captureDevicePosition)
}
}
Expand Down Expand Up @@ -199,7 +200,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
*Notes: if `stopScanningWhenCodeIsFound` is sets to true (default behaviour), each time the scanner found a code it calls the `stopScanning` method.*
*/
public func startScanning() {
sessionQueue.async {
sessionQueue.async { [weak self] in
guard let self = self else { return }
guard !self.session.isRunning else { return }

self.session.startRunning()
Expand All @@ -212,7 +214,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat

/// Stops scanning the codes.
public func stopScanning() {
sessionQueue.async {
sessionQueue.async { [weak self] in
guard let self = self else { return }
guard self.session.isRunning else { return }

self.session.stopRunning()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ public class QRCodeReaderViewController: UIViewController {

view.backgroundColor = .black

codeReader.didFindCode = { [weak self] resultAsObject in
codeReader.didFindCode = { [weak self, weak builder] resultAsObject in
if let weakSelf = self {
if let qrv = builder.readerView.displayable as? QRCodeReaderView {
if let qrv = builder?.readerView.displayable as? QRCodeReaderView {
qrv.addGreenBorder()
}
weakSelf.completionBlock?(resultAsObject)
weakSelf.delegate?.reader(weakSelf, didScanResult: resultAsObject)
}
}

codeReader.didFailDecoding = {
if let qrv = builder.readerView.displayable as? QRCodeReaderView {
codeReader.didFailDecoding = { [weak builder] in
if let qrv = builder?.readerView.displayable as? QRCodeReaderView {
qrv.addRedBorder()
}
}
Expand Down