I work on an iOS app that displays images that often contain text, and I'm adding support for ImageAnalysisInteraction
as described in this WWDC 2022 session. I have gotten as far as making the interaction show up and being able to select text and get the system selection menu, and even add my own action to the menu via the buildMenuWithBuilder
API. But what I really want to do with my custom action is get the selected text and do a custom lookup-like thing to check the text against other content in my app.
So how do I get the selected text from an ImageAnalysisInteraction
on a UIImageView
? The docs show methods to check if there is selected text, but I want to know what the text is.
There's an API for this in iOS 17 and later! ImageAnalysisInteraction.selectedText. https://developer.apple.com/documentation/visionkit/imageanalysisinteraction/4176689-selectedtext