1
votes

I encountered a strange bug where UIAccessibilityIsGuidedAccessEnabled starts returning false even after guided access has been enabled in settings and I activated it by triple tapping the home button and successfully seeing the guided access is enabled message.

Here is a sample code to show what I am doing.

override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(guidedAccessStatusChanged(notification:)), name: NSNotification.Name.UIAccessibilityGuidedAccessStatusDidChange, object: nil)
}

@objc func guidedAccessStatusChanged(notification: NSNotification) {

    if UIAccessibilityIsGuidedAccessEnabled() {
        print("Guided access is enabled")
    }  else {
        // The program randomly started just displaying this even after guided access is enabled.
        print("Guided access is disabled")
    }
}

At first I thought it might be a timing issue and even tried delaying my guided access status check but that did not work either.

1

1 Answers

0
votes

You can also define an observer with the related code block directly being provided:

_ = NotificationCenter.default.addObserver(forName: NSNotification.Name.UIAccessibilityGuidedAccessStatusDidChange, object: nil, queue: OperationQueue.main, using: { _ in
    if UIAccessibilityIsGuidedAccessEnabled() {
        print("Guided access is enabled")
    }  else {
        // The program randomly started just displaying this even after guided access is enabled.
        print("Guided access is disabled")
    }
})

However. One has to be aware of the guided mode will be set to disabled, as soon as the user is on the 'guided access setting's screen', where you can define, whether you do allow touches, specific timeframe limitations etc. This view is displayed, after you have touched 3x again the home button and entered the pin code for leaving the guided mode.

Although the guided mode is not completely disabled in this mode, it is also not enabled. Maybe this could be the reason, why it is "randomly" set to being disabled?

If not, maybe you can also clarify a bit further, what is being done on User/App-side, when these random occurrences appear.