Skip to content

Commit

Permalink
Update with review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ba01ei committed Sep 26, 2022
1 parent fa013b7 commit fd31f53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
31 changes: 12 additions & 19 deletions Agrume/AgrumeCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,8 @@ final class AgrumeCell: UICollectionViewCell {
imageView.setGifImage(image)
} else {
imageView.image = image
if enableLiveText {
if #available(iOS 16, *) {
if let image = image {
Task {
await analyzeImage(image)
}
}
}
if #available(iOS 16, *), enableLiveText, let image = image {
analyzeImage(image)
}
}
if !updatingImageOnSameCell {
Expand Down Expand Up @@ -497,25 +491,24 @@ extension AgrumeCell: UIScrollViewDelegate {
}

@available(iOS 16, *)
private func analyzeImage(_ image: UIImage) async {
private func analyzeImage(_ image: UIImage) {
guard ImageAnalyzer.isSupported else {
return
}

let interaction = ImageAnalysisInteraction()
imageView.addInteraction(interaction)

let analyzer = ImageAnalyzer()
let interaction = await MainActor.run {
let interaction = ImageAnalysisInteraction()
imageView.addInteraction(interaction)
return interaction
}
let configuration = ImageAnalyzer.Configuration([.text, .machineReadableCode])
do {
let analysis = try await analyzer.analyze(image, configuration: configuration)
await MainActor.run {

Task { @MainActor in
do {
let analysis = try await analyzer.analyze(image, configuration: configuration)
interaction.analysis = analysis
interaction.preferredInteractionTypes = .automatic
} catch {
print(error.localizedDescription)
}
} catch {
}
}
}
16 changes: 7 additions & 9 deletions Example/Agrume Example/LiveTextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import VisionKit

final class LiveTextViewController: UIViewController {
@IBAction private func openImage(_ sender: Any) {
if #available(iOS 16, *) {
if ImageAnalyzer.isSupported {
let agrume = Agrume(
image: UIImage(named: "TextAndQR")!,
enableLiveText: true
)
agrume.show(from: self)
return
}
if #available(iOS 16, *), ImageAnalyzer.isSupported {
let agrume = Agrume(
image: UIImage(named: "TextAndQR")!,
enableLiveText: true
)
agrume.show(from: self)
return
}

let alert = UIAlertController(title: "Not supported on this device", message: "Live Text is available for devices with iOS 16 (or above) and A12 (or above) Bionic chip (iPhone XS and later, physical device only)", preferredStyle: .alert)
Expand Down

0 comments on commit fd31f53

Please sign in to comment.