Live Text

RSS for tag

Enable text interactions, translation, data detection, and QR code scanning within any image view on iOS, iPadOS, or macOS.

Live Text Documentation

Posts under Live Text tag

8 Posts
Sort by:
Post marked as solved
2 Replies
478 Views
Hello everyone, first let me say a few words about myself. I am an IT student and I want to learn and develop some applications in Swift. Now I am working on one application and I need a barcode scanner to complete it. So I need help from someone who can help me with a simple barcode scanner. My idea is that the barcode will be on one screen and they have to read the code and write it to a variable. That's my idea. I will appreciate the full code or help. thank you for answer
Posted
by MORADENS.
Last updated
.
Post not yet marked as solved
0 Replies
432 Views
I have a live text implementation on the following LiveTextImageView. However, after the view loads and the analyze code is run, none of the delegate methods fire when I interact with the Live View. Selecting text does not fire the textSelectionDidChange method, nor does highlightSelectedItemsDidChange fire when the live text button in the bottom right is pressed. I tried a few different implementations, including an approach where the delegate was defined on a separate class. I am running this on a iPhone 12 Pro I recently updated to 17.0.3. My goal is to be able to provide additional options to the user beyond the default live-text overlay options, after identifying when they have finished selecting text. // // LiveTextImageView.swift // import UIKit import SwiftUI import VisionKit class ImageAnalyzerWrapper { static let shared = ImageAnalyzer() private init() { } } struct LiveTextImageViewRepresentable: UIViewRepresentable { var image: UIImage func makeUIView(context: Context) -> LiveTextImageView { return LiveTextImageView(image: image) } func updateUIView(_ uiView: LiveTextImageView, context: Context) { } } class LiveTextImageView: UIImageView, ImageAnalysisInteractionDelegate, UIGestureRecognizerDelegate { var capturedSelectedText: String? let analyzer = ImageAnalyzerWrapper.shared let interaction = ImageAnalysisInteraction() init(image: UIImage) { super.init(frame: .zero) self.image = image let photoWrapper = PhotoWrapper(rawPhoto: image) let resizedPhoto = photoWrapper.viewportWidthCroppedPhoto(padding: 40) self.image = resizedPhoto self.contentMode = .scaleAspectFit self.addInteraction(interaction) interaction.preferredInteractionTypes = [] interaction.analysis = nil analyzeImage() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func analyzeImage() { if let image = self.image { Task { let configuration = ImageAnalyzer.Configuration([.text]) do { let analysis = try await analyzer.analyze(image, configuration: configuration) self.addInteraction(interaction) interaction.delegate = self interaction.analysis = analysis interaction.preferredInteractionTypes = .textSelection } catch { print("Error in live image handling") } } } } func interaction( _ interaction: ImageAnalysisInteraction, highlightSelectedItemsDidChange highlightSelectedItems: Bool) async { print("Highlighted items changed") } func interaction(_ interaction: ImageAnalysisInteraction, shouldBeginAt point: CGPoint, for interactionType: ImageAnalysisInteraction.InteractionTypes) async -> Bool { return interaction.hasInteractiveItem(at: point) || interaction.hasActiveTextSelection } func textSelectionDidChange(_ interaction: ImageAnalysisInteraction) async { print("Changed!") if #available(iOS 17.0, *) { capturedSelectedText = interaction.text print(capturedSelectedText ?? "") } } }
Posted Last updated
.
Post not yet marked as solved
0 Replies
766 Views
We are using URL encoded in QR code to open our web application. When user scans QR using the default Camera app on iPhone, upon clicking the link iOS opens the webpage on safari browser. Our URL looks like this "https://abc.com?qrdata=1", "https://abc.com?qrdata=2", "https://abc.com?qrdata=3". The URL query parameter(qrdata) differs for different process in the web app. So when so each QR code has same domain but different query parameters. If the user scans QR for https://abc.com?qrdata=1, the web page is opened on safari without any issue. If user scansQR for https://abc.com?qrdata=2 after the first QR code then for some reason on first attempt Safari is loading the previously scanned URL, in this case https://abc.com?qrdata=1. The change in query params is not received correctly by Safari. If we scan the new QR code twice then works on 2nd attempt to scan the QR. I can see from the history that the URL scanned is not the right url This is issue only on Safari iOS devices, on anyother browser works as expected.
Posted Last updated
.
Post not yet marked as solved
0 Replies
391 Views
I was switching the Detector scanner from QR to Rectangle type of detection but on Rectangle type of detection I cannot take the feature.messageString out of CIRectangleFeature, while on CIQRCodeFeature it works. Only what I had changed was ofType: CIDetectorTypeQRCode into CIDetectorTypeRectangle and features as? [CIQRCodeFeature] into features as? [CIRectangleFeature] here is the code func processQRCodeImage(_ image: UIImage) { var qrCodeLink = "" let detector: CIDetector = CIDetector(ofType: CIDetectorTypeRectangle, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])! let ciImage: CIImage = CIImage(image: image)! let features = detector.features(in: ciImage) if let features = features as? [CIRectangleFeature] { for feature in features { qrCodeLink += feature.messageString! // Value of type 'CIRectangleFeature' has no member 'messageString' COMPILE ERROR } } if qrCodeLink.isEmpty { failedQRCoderead() } else { found(code: qrCodeLink) onBackPressed?() } }
Posted
by MakTuzla.
Last updated
.
Post not yet marked as solved
0 Replies
615 Views
After loading iOS 17 on my iPhone 13 pro max it won't send the messages I type on my phone to iPad or Mac computers. I have restarted all iMessage settings several times checked message forwarding setting all are in order. I also checked the Apple ID it is the same on all devices. Any suggestions would be appreciated to fix the problem thanks.
Posted
by Rnmusik.
Last updated
.
Post not yet marked as solved
0 Replies
927 Views
Hello there! Really excited about this year's additions to ImageAnalysisInteraction, especially the selectedText. Thank you! My question is if there's a way to have multiple interactions for a given image analysis. For example, instead of being able to make just one text selection, I would like to support multiple. In theory, I know multiple UIInteraction-conforming objects can be added to any view but I'm unsure if this is possible with ImageAnalysisInteraction. I'm willing to create a custom UIInteraction, if you see a potential way forward there (would love to hear any ideas!). Side question/feature request: UITextSelectionDisplayInteraction, which I assume ImageAnalysisInteraction might be using internally, allows handleViews customizations and others. I would be super useful if that was exposed through ImageAnalysisInteraction as well! Looking forward to hearing your ideas. TIA!
Posted Last updated
.