Disable sleep/wake when in Autonomous Single App Mode (ASAM)

If a user enables/disables Guided Access, they can modify the session settings to disable the top (sleep/wake) button.

In Single App Mode (SAM), there is a payload option for disabling the sleep/wake button via Mobile Device Management (MDM).

In Autonomous Single App Mode (ASAM), there doesn't appear to be any way to disable the top button. ASAM does not honor the Guided Access sessions settings, and there is no payload option in the MDM.

This is a glaring issue especially when ASAM is marketed as the solution for apps in a medical setting where the app is trading hands from a medical professional to a patient. Our app is used during a lengthy procedure and does not function properly if the patient puts the iPad to sleep. We're stuck asking our medical professionals to put the iPad in Guided Access, but the user experience is clunky and would be much improved by implementing ASAM.

Is there some little-known API for disabling the sleep/wake button during ASAM that I'm just missing?

Did you find a solution to this? EXACT same problem/observations here.

This needs a solution.

Sort of. The following is a workaround:

Summary

An iOS device that receives a notification while asleep will turn on the display briefly to show the notification on the lock screen.

An iOS device with ASAM enabled cannot be locked, so a received notification will instead wake up the display with the app open. Note that the banner does not display. There is no visual indicator that a notification was received.

We take advantage of this mechanism to wake up our app via a local notification whenever our app is backgrounded while in ASAM.

Caveats

  • This only works if the user explicitly allows notification permissions for the app. I recommend gating the app from use if these permissions are disabled and re-directing the user to Settings.
  • The iPad cannot be in "Do Not Disturb" which is something that MDMs are currently unable to disable. This is the biggest risk to this workaround.
  • The notification will be queued in the Notification Center. Once ASAM is disabled, these notifications will be visible there.

Implementation

  1. Request user notification permissions
UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) { /* ... */ }
  1. Whenever the app is in ASAM and the iPad is put to sleep, schedule a local notification to fire within a couple seconds.
func applicationDidEnterBackground(_ application: UIApplication) {
  if asamEnabled /* a flag we we track globally */ {
    let content = UNMutableNotificationContent()
    content.title = "Please do not put the app to sleep during an active test."
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false)
    let request = UNNotificationRequest(identifier: "keepAppForegrounded", content: content, trigger: trigger)
    UNUserNotificationCenter.current().add(request)  
  }
}
Disable sleep/wake when in Autonomous Single App Mode (ASAM)
 
 
Q