Search code examples
iosswiftxcodelivetext

Check if Apple LiveText is available?


I want to add apple live text support using a scan button. But I know that it is available for iOS 15+ and A12 processors and above. How do I check that in Swift?


Solution

  • 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.