If you need multiple links embedded in some text (like the classic T&Cs and Privacy policy), the easiest is to use a UITextView & Attributed Strings, and it will work beautifully with VoiceOver. You'll be even able to navigate through links.

App shows a registration form with username and password textfields and a text that says “I agree with the Privacy Policy and the Terms and Conditions” Both Privacy Policy and Terms and Conditions are links. There is some code that shows you how you can use a text field with attributed strings and the link attribute. Implementing the UITextViewDelegate has a function to capture link interactions so they can be handled.

In the example, VoiceOver would say: “I agree with the Privacy Policy and the Terms and Conditions, link”. Swipe down, should announce: “Privacy Policy, link” and you can double tap to open it. Swiping down one more time announces: “Terms and Conditions, link”.

Example code in the image:

let textView = UITextView()
let string = "I agree with the Privacy Policy and the Terms and Conditions"
let attributedString = NSMutableAttributedString(string: string)

attributedString.addAttribute(.link,
                              value: "https://www.yourdomain.com/pp",
                              range: NSRange(location: 17, length: 14))
attributedString.addAttribute(.link,
                              value: "https://www.yourdomain.com/tac",
                              range: NSRange(location: 40, length: 20))
textView.attributedText = attributedString

extension ViewController: UITextViewDelegate {
    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        UIApplication.shared.open(URL)
        return true
    }
}

You may also find interesting...

The .summaryElement accessibility trait causes VoiceOver to announce that element when the app starts. The element won't get the focus though, and the order is not affected. A candidate for this trait could be the rings info in the Activity app.

To capture the gesture, you can override the accessibilityPerformEscape() function. In there you can dismiss your view, and return true if you could successfully handle it. https://developer.apple.com/documentation/objectivec/nsobject-swift.class/accessibilityperformescape()

Configuring the header accessibility trait, when appropriate, is one of my favourite accessibility quick wins. In this example, you need a single swipe down, instead of 12 swipes to the right to get to from Podcasts to Artists, in the app.

Created in Swift with Ignite.

Supporting Swift for Swifts