How to Know a Device Is Available to Use Capturetextfromcamera API

How to know a device is available to use captureTextFromCamera API?

One simple condition:

UITextField().canPerformAction(#selector(UIResponder.captureTextFromCamera(_:))

Tests both device support and language setting support

Check if Apple LiveText is available?

Don't check for the iOS 15+ and processor A12+, check for the iOS 15's 'Live Text'feature support. Create a helper method with the following check that will return whether the device support live text or not



Sample:

var isSupported = true
if #available(iOS 15.0, *) {
let check = UITextField().canPerformAction(#selector(UIResponder.captureTextFromCamera(_:)), withSender: nil)
isSupported = check
} else {
isSupported = false
}

print(isSupported)

Using the above condition will return false in the case of the device having iOS 15+ but not having hardware support.

How to Remove UIMenuController Default Items In Swift

I tried this but it worked for my by subclassing the WebView and overriding canPerformAction method, inside which I manually removed the default options.

override func canPerformAction(_ action: Selector, withSender sender: AnyObject?) -> Bool {
if action == #selector(cut(_:)) {
return false
}
if action == #selector(paste(_:)) {
return false
}
if action == #selector(select(_:)) {
return false
}
if action == #selector(selectAll(_:)) {
return false
}
...

return super.canPerformAction(action, withSender: sender)
}

I referred to this answer by Ike10 and it had worked for me. Give it a shot.



Related Topics



Leave a reply



Submit