Inactivity
I needed to detect idle mode on a SwiftUI app for a kiosk, so I did it.
Usage
Important: You must set the
Principal classof your app toInactivity.InactivityApplicationin your info.plist.
This is an example:
InactivityWatcherView { proxy in
InactiveView {
proxy.becomeActive(timeout: 5)
}
.transition(.opacity)
ActiveView()
.transition(.opacity)
}
Also, you can perform an action when the state changes:
Text("Example")
.onInactivityStateChanged { state in print("Going to \(state)") }
Finally, it is possible to access to the InactivityWatcher class using the shared attribute of the InactivityApplication:
InactivityApplication.shared.watcher.startWatch(timeout: 120)
Enjoy!