UITextView with two links doesn't allow selecting the last link in voice over.

Originator:galiak
Number:rdar://FB7721755 Date Originated:June 1st, 2020
Status:Open Resolved:
Product:UIKit Product Version:iOS 13
Classification:Incorrect/Unexpected Behavior Reproducible:Yes
 
Summary:  We have a UITextView with a NSAttributedString that contains two links. We are unable to use voice over to select the 2nd link in iOS 13.

In iOS 13, setting `UITextView.editable = NO`, `selectable = YES`, and `dataDetectorTypes = UIDataDetectorTypeLink`, voice over detects the links, but will not allow individual selection.  The “swipe up and down” gesture is non responsive, not allowing switching between links.  Therefore the first link is always the current link, so when double tapping to select a link, the first link is always selected.

It seems that in iOS 12, setting `UITextView.editable = NO`, `selectable = YES`, and `dataDetectorTypes = UIDataDetectorTypeLink`, correctly renders the links and allows individual link selection.

We set:
    textView.editable = NO;
    textView.scrollEnabled = NO;
    textView.selectable = YES; 
    textView.dataDetectorTypes = UIDataDetectorTypeLink;
    textView.delegate = self;

and implement the relevant method:

@interface MyViewController () <UITextViewDelegate>
// …
@end

@implementation MyViewController
// …

- (BOOL)textView:(UITextView *)textView
    shouldInteractWithURL:(NSURL *)URL
                  inRange:(NSRange)characterRange
              interaction:(UITextItemInteraction)interaction {
   if (someCondition) {
      return NO;
   }  else {
      return YES;
   }
}

We then use the following attributed text:

  var attributedText: NSAttributedString {
    typealias AttrDict = [NSAttributedString.Key: Any]
    let urlAttr: AttrDict = [.link: "https://www.google.com/search?q=lorem+ipsum"]
    let customLinkAttr: AttrDict = [.link: "catalog://"]  // A custom link.

    let attributedText = NSMutableAttributedString()
    attributedText.append(NSAttributedString(string: "Lorem ipsum", attributes: urlAttr))
    attributedText.append(NSAttributedString(string: " dolor sit amet, ", attributes: nil))
    attributedText.append(NSAttributedString(string: "consectetur adipiscing elit, sed do eiusmod", attributes: nil))
    attributedText.append(NSAttributedString(string: " tempor ", attributes: customLinkAttr))
    attributedText.append(NSAttributedString(string: "incididunt ut labore magna aliqua.", attributes: nil))
    return attributedText
  }

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!