How to Receive Callbacks for UIAccessibilityAction Methods Like accessibilityPerformMagicTap()?

I’ve tried implementing the accessibilityPerformMagicTap() method in a specific UIViewController, its view, and even in AppDelegate, but I am not receiving any callbacks.

I directly overrode this method in the mentioned areas, but it never gets triggered when performing a magic tap.

How can I properly observe and handle the accessibilityPerformMagicTap() action?

Can you double-check that you're performing the correct gesture as it appears in Settings > Accessibility > VoiceOver > Commands > Touch Gestures > Magic Tap?

When Magic Tap is performed on a view, VoiceOver checks whether the view is overriding the function and calls it. If not, VoiceOver goes and checks on its parent view, continuously until it finds an override or it falls off and does nothing. No need to place it in the AppDelegate.

@Frameworks Engineer

Settings > Accessibility > VoiceOver > Commands > Touch Gestures > Magic Tap

The default two-finger double tap is assigned to the Magic Tap gesture, and it works as expected in first-party apps like the Clock and Podcasts apps. However, it doesn’t seem to work in my app.

Below, I’ve attached a sample code for reference.


Strangely, when I perform the Magic Tap in my app, it starts playing a podcast instead.

import UIKit

class SecondaryVC : UIViewController{
    private var actionButton : UIButton = {
        let button = UIButton(type: .system)
        button.backgroundColor = .systemGreen
        button.setTitle("Add", for: .normal)
        button.layer.cornerRadius = 8
        return button
    }()

     init(){
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad(){
        super.viewDidLoad()
        view.backgroundColor = .systemTeal
        addSubViews()
    }

    override class func accessibilityPerformMagicTap() -> Bool {
        print(">>>> SecondaryVC accessibilityPerformMagicTap")
        return true
    }

    override class func accessibilityPerformEscape() -> Bool {
        print(">>>> secodaryVC EscapeAction")
        return true
    }

    override class func accessibilityDecrement() {
        print(">>>> accessibilityDecrement")
    }

    override class func accessibilityIncrement() {
        print(">>>> accessibilityIncrement")
    }

    private func addSubViews(){
        view.addSubview(actionButton)
        actionButton.translatesAutoresizingMaskIntoConstraints = false
        actionButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor,constant: 16).isActive = true
        actionButton.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant: 16).isActive = true
        actionButton.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant: -16).isActive = true
    }
}

How to Receive Callbacks for UIAccessibilityAction Methods Like accessibilityPerformMagicTap()?
 
 
Q