3

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

Tom
  • 2,358
  • 1
  • 15
  • 30

1 Answers1

2

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.

Community
  • 1
  • 1
Matthew Seaman
  • 7,952
  • 2
  • 37
  • 47
  • 1
    Interesting that Apple's documentation on this function says that the return value is "true if the user has enabled Guided Access in Settings; otherwise, false." It makes no mention about being active or inactive based on the home button triple-click. Is this a documentation error? – Christopher Whidden May 22 '16 at 18:21
  • @ChristopherWhidden Not positive, but this appears to be what other sources indicate. – Matthew Seaman May 22 '16 at 18:22
  • Thanks Christopher, all though not the answer I wanted to hear but as your answer is accurate I have given the bounty. Maybe I will raise this issue with apple – Tom May 22 '16 at 20:10