swiftguided-access

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


Solution

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