How can I programmatically enable Guided Access (Kiosk mode) on an iPhone?

♀尐吖头ヾ 提交于 2019-11-26 10:36:15

问题


Question

How do I automate Guided Access mode on an iPhone? I will need to automate the enabling and removal of this feature

Background This application from the State of Iowa uses an iOS app to display your drivers license. The issue is that after handing your phone over to authorities, they have full access to the device.

If I have the source code to this, or a similar application, how can I require a password when switching out of temporary \"Kiosk mode\", so that photos, emails or text messages are not available from either the phone, or (ideally) from USB.

I found this similar solution for Android, but am now looking for an iOS solution


回答1:


You can enter and exit guided access mode from within your app. However, to do so the device has to be supervised, and have an MDM profile installed that has the app's bundle ID in the list of applications that can request guided access mode (the key is autonomousSingleAppModePermittedAppIDs.

Once that is done, to enter guided access you do this:

UIAccessibility.requestGuidedAccessSession(true){
    success in
    print("Request guided access success \(success)")
}



回答2:


Below iOS 7

You can't put iOS device into Kiosk mode programmatically, also you can't do anything on your app for making it a Kiosk app (You can't disable the home button events programmatically and you can't get the events in your app)

For making the device to work on Kiosk mode, you can use Apple's Guided Access. But you can't enable it programmatically. For more info check here


iOS 7 and 7+

You can use:

void UIAccessibilityRequestGuidedAccessSession(BOOL enable, void(^completionHandler)(BOOL didSucceed))

Reference UIAccessibilityRequestGuidedAccessSession

UIAccessibilityRequestGuidedAccessSession

Transitions the app to or from Single App mode asynchronously. Declaration

Swift

func UIAccessibilityRequestGuidedAccessSession(_ enable: Bool, _ completionHandler: ((Bool) -> Void)!)

Objective-C

void UIAccessibilityRequestGuidedAccessSession ( BOOL enable, void (^completionHandler)(BOOL didSucceed) ); Parameters enable

Specify YES to put the device into Single App mode for this app or NO to exit Single App mode.

completionHandler

The block that notifies your app of the success or failure of the operation. This block takes the following parameter: didSucceed

If YES, the app transitioned to or from Single App mode successfully. If NO, the app or device is not eligible for Single App mode or there was some other error. Discussion

You can use this method to lock your app into Single App mode and to release it from that mode later. For example, a test-taking app might enter this mode at the beginning of a test and exit it when the user completes the test. Entering Single App mode is supported only for devices that are supervised using Mobile Device Management (MDM), and the app itself must be enabled for this mode by MDM. You must balance each call to enter Single App mode with a call to exit that mode.

Because entering or exiting Single App mode might take some time, this method executes asynchronously and notifies you of the results using the completionHandler block. Import Statement

import UIKit Availability

Available in iOS 7.0 and later.

Also you can use UIAccessibilityIsGuidedAccessEnabled for checking whether Guided Access is enabled or not.




回答3:


As per documentation, There are two ways of enabling your iOS app to run in kiosk mode.

Configuration Profile: With the help of mobile device management (MDM), we can create an enterprise configuration profile and push this to device using any MDM, popularly known MobileIron for example or with the help of any iPhone configuration utility. Once this profile is installed the first app that is launched when the device is rebooted will be the only app that will run until you reboot the device again.

Guided access (iOS 6 and above): Since iOS 6, we can achieve this using two methods namely Guide Access & Supervised Access. These both methods deals with Accessibility Control features such as allowing user to have restricted access to their device. This can be achieved only if we have full access to the device.

We can achieve setting up Kiosk Mode in iOS App programmatically in iOS 7 using an UIKit method UIAccessibilityRequestGuidedAccessSession. As per the apple developer documentation, 'UIAccessibilityRequestGuidedAccessSession will transitions the app to or from Single App mode asynchronously'.

As given in the apple developer document:

UIAccessibilityRequestGuidedAccessSession

Transitions the app to or from Single App mode asynchronously.

void UIAccessibilityRequestGuidedAccessSession(BOOL enable, void(^completionHandler)(BOOL didSucceed))

Parameters

enable

Specify YES to put the device into Single App mode for this app or NO to exit Single App mode.

completionHandler

The block that notifies your app of the success or failure of the operation. This block takes the following parameter:

didSucceed

If YES, the app transitioned to or from Single App mode successfully. If NO, the app or device is not eligible for Single App mode or there was some other error. Discussion You can use this method to lock your app into Single App mode and to release it from that mode later. For example, a test-taking app might enter this mode at the beginning of a test and exit it when the user completes the test. Entering Single App mode is supported only for devices that are supervised using Mobile Device Management (MDM), and the app itself must be enabled for this mode by MDM. You must balance each call to enter Single App mode with a call to exit that mode. Because entering or exiting Single App mode might take some time, this method executes asynchronously and notifies you of the results using the completionHandlerblock.

Availability
Available in iOS 7.0 and later.

See Also

UIAccessibilityIsGuidedAccessEnabled

Declared In

UIAccessibility.h



回答4:


From what I understand this cannot be done using code. On a non jailbroken device and then you would need to create a daemon that runs as a listener.

The closest thing you can do is set up "Guided Access" on your device and link it to the triple home button press.

More information about guided access can be found here




回答5:


This cannot be done programmatically. "Guided Access" is the only solution.

Refer to http://voice4uaac.com/tips/guided-access-ios6/ for Screenshot based example.



来源:https://stackoverflow.com/questions/27488537/how-can-i-programmatically-enable-guided-access-kiosk-mode-on-an-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!