Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stranger Behavior with UIAccessibilityIsGuidedAccessEnabled Bool - SWIFT

My app wants to recognize whether or not the user has gone into guided access mode.

I currently have a NSNotification setup which triggers a boolean provided by apple but for some reason it is always providing a false negative.

        NSNotificationCenter.defaultCenter() .addObserver(self, selector: #selector(guidedAccessChanged), name: UIAccessibilityGuidedAccessStatusDidChangeNotification, object: nil)

will trigger the following method

    func guidedAccessChanged () {

//        NSLog(@"Accessabilitiy enabled: %@", UIAccessibilityIsGuidedAccessEnabled() ? @"YES" : @"NO");

        print("Accessabilitiy enabled: \(UIAccessibilityIsGuidedAccessEnabled() ? "YES" : "NO" )")

        if (!UIAccessibilityIsGuidedAccessEnabled()){

            print("guided access Off")

        }
        else{
            print("guided access On")

        }

    }

But for some reason the logs are returning

guided access Off

like image 290
Tom Avatar asked Feb 23 '26 20:02

Tom


1 Answers

The function and notification should reflect whether Guided Access is enabled and active for your app, not necessarily when it is on in Settings.

So if Guided Access is on in Settings, I don't know of public API that is going to let you know, but if it is currently running (i.e. the user has triple-tapped the home button to explicitly enter Guided Access for your app, set their preferred options, and tapped start) UIAccessibilityIsGuidedAccessEnabled() should return true. But only then.

See the comments on the accepted answer of this question

Also see this question.

like image 98
Matthew Seaman Avatar answered Feb 26 '26 09:02

Matthew Seaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!