0

I know how to put app into Single app mode programmatically, provided that Autonomous single app mode persimmon is granted by MDM server to App.

This link have detail description about how to lock app in single app mode too.

Code to Apply single app mode as below -

UIAccessibilityRequestGuidedAccessSession(true){
            success in
            completionBlock(success)
        }

My Question/Requirement is, detect if app is running in Autonomous single single app mode or UIAccessibilityRequestGuidedAccessSession is enabled, if it's enabled then only show alert to user and ask if he wish to disable Single App mode.

I Tried to detect using UIAccessibilityIsGuidedAccessEnabled() but it's of no use, as return value is always false.

Sheshnath
  • 3,293
  • 1
  • 32
  • 60
  • https://developer.apple.com/documentation/uikit/1615173-uiaccessibilityisguidedaccessena?language=objc – Akaino Aug 31 '18 at 07:01

2 Answers2

1

You can use BOOL UIAccessibilityIsGuidedAccessEnabled(void); to get that information.

Source@AppleDocs

You could also try to add UIGuidedAccessRestrictionDelegate and then react to

func UIGuidedAccessRestrictionStateForIdentifier(_ restrictionIdentifier: String) -> UIGuidedAccessRestrictionState

Remember though, guided access needs to be enabled by the user (triple tap home button). Not from the settings!

Akaino
  • 1,025
  • 6
  • 23
  • I Tried to detect using UIAccessibilityIsGuidedAccessEnabled() but it's of no use, as return value is always false. – Sheshnath Aug 31 '18 at 07:19
  • It works just fine as the docs state: `Return Value YES when a Guided Access session is currently active; otherwise, NO.` So there seems to be something wrong with your code. Please share what you tried. – Akaino Aug 31 '18 at 07:24
1

So @Akaino answer is right, but UIAccessibilityIsGuidedAccessEnabled method wasn't working as expected due to i used to apply code below on didFinishLaunchingWithOptions hence it wasn't working properly

UIAccessibilityRequestGuidedAccessSession(true){
            success in
            completionBlock(success)
        }

When i applied same code above on viewDidLoad() method, UIAccessibilityIsGuidedAccessEnabled is working as expected.

Sheshnath
  • 3,293
  • 1
  • 32
  • 60