Skip to content

Commit 4029dc0

Browse files
authored
Merge pull request #48 from what3words/bug/fix-crash-ios17
Bug/fix crash ios17
2 parents f4f476a + 584f007 commit 4029dc0

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Sources/W3WSwiftComponentsOcr/Camera/W3WOcrCamera.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,25 @@ public class W3WOcrCamera: W3WVideoStream {
9090
#if targetEnvironment(simulator)
9191
imageProcessor.start()
9292
#else
93-
thread.async {
93+
thread.async { [weak self] in
94+
guard let self else { return }
9495
print(#function, "async ", "START")
9596
self.session?.beginConfiguration()
9697
self.session?.commitConfiguration()
9798
self.session?.startRunning()
99+
self.startCountdown()
98100
print(#function, "async ", "STOP")
99101
}
100102
#endif
101-
103+
104+
}
105+
106+
private func startCountdown() {
102107
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
103108
guard let self else { return }
104109
self.onCameraStarted?()
105110
}
106111
}
107-
108-
109112
/// tell the camera to stop producing images
110113
public func stop() {
111114
//print("camera.stop()")
@@ -114,9 +117,14 @@ public class W3WOcrCamera: W3WVideoStream {
114117
imageProcessor.stop()
115118
disconnectInputAndOutput()
116119
#else
117-
thread.async {
120+
121+
thread.sync { [weak self] in
122+
guard let self else { return }
123+
self.session?.beginConfiguration()
124+
self.session?.commitConfiguration()
118125
self.session?.stopRunning()
119126
self.disconnectInputAndOutput()
127+
self.session = nil
120128
}
121129
#endif
122130
}

Sources/W3WSwiftComponentsOcr/W3WOcrViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,13 @@ open class W3WOcrViewController: W3WViewController {
447447
self?.ocrView.unset(camera: c)
448448
}
449449

450+
self?.ocrView.removeBoxes()
451+
450452
#if canImport(W3WOcrSdk)
451453
self?.ocr?.stop {
452454
completion()
453455
}
454456
#endif
455-
456-
self?.ocrView.removeBoxes()
457457
}
458458
}
459459

0 commit comments

Comments
 (0)