I needed to detect idle mode on a SwiftUI app for a kiosk, so I did it.

Related tags

Utility Inactivity
Overview

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 class of your app to Inactivity.InactivityApplication in 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!

You might also like...
This iOS framework allows settings to be in-app in addition to or instead of being in the Settings app.
This iOS framework allows settings to be in-app in addition to or instead of being in the Settings app.

InAppSettingsKit InAppSettingsKit (IASK) is an open source framework to easily add in-app settings to your iOS or Catalyst apps. Normally iOS apps use

TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.
TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.

TypeStyle TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app. Featu

This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app.

🛠 X-BundleIcon This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app. xbi com.apple.Safari 16 /

Recreating a fully functional version of iOS 4 in SwiftUI.
Recreating a fully functional version of iOS 4 in SwiftUI.

Updates: Version 1.0 is currently available 🎉 While I work on fixing an issue in Xcode 12.5+ with LazyVGrid, I recommend you build using Xcode 12.4 a

SnippetsLibrary - Code snippets library for SwiftUI Devs.
SnippetsLibrary - Code snippets library for SwiftUI Devs.

SnippetsLibrary is a helpful tool for SwiftUI developers to help with their daily coding life. SnippetsLibrary contains all the needed code snippets for you to view, edit, or add more and more. This will make your daily work easier and faster.

Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data.

Pigeon 🐦 Introduction Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data. It is heavily inspired by React Qu

Safe and fast access to SwiftUI PreviewDevice

SafePreviewDevice Motivation At WWDC 2019, Apple announced SwiftUI a new library for building UI in a simple and fast way. Xcode’s SwiftUI preview let

Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.
Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.

SheeKit Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of UISheetPresentationController and other UIKit features. Overview She

*Random Smooth Cloudy* Noise for SwiftUI
*Random Smooth Cloudy* Noise for SwiftUI

Noise Generate random smooth cloudy noise. Install Swift Package .

Comments
  • Not an issue - more like a question

    Not an issue - more like a question

    Hi,

    Could You tell me please how exactly I Can use it and what exactly should be in the plist file . What I want to achieve is to logoff user after some time of idle ...

    Thank in advance.

    opened by Helicobacter1234 5
  • Added feature to support automatic inactivity trigger

    Added feature to support automatic inactivity trigger

    This pull request introduces the concept of an inactivity trigger type: manual and automatic. Manual is defined as a specific interaction such as tapping on a button. In response to the button tap you must call startWatch(). This is what happens in your sample app, InactivityExample, when the user taps on Start. Automatic is defined as any activity at all from the user and startWatch() is called automatically.

    I have developed this for a slightly different use case than your original. In my use case I need to return to the login screen if the app has been inactive for a specific period of time. Any user interaction would be considered active for me.

    I believe these changes will work for both of our uses cases. I have tested my changes with InactivityExample and it looks like it still works correctly.

    opened by thespeakgeek 3
  • How to access InactivityWatcher

    How to access InactivityWatcher

    I would like to access the InactivityWatcher.shared instance from my application. The README says the way to do this is by

    accessing the shared attribute of the InactivityApplication.

    I see this was possible in a previous version of InactivityApplication.swift. However it appears that the code was removed during refactoring. Is there any other way to do this?

    opened by thespeakgeek 1
  • License?

    License?

    @heltena Would you consider adding a license to your code? By default no one can use or modify it. I like what you have developed and think others would find it useful too.

    See reference here: No License

    opened by thespeakgeek 1
Releases(1.0.3)
Owner
Helio Tejedor
Helio Tejedor
Sync Slack status to macOS Monterey Focus mode

SyncFocusWithSlack Sync Slack status to macOS Monterey Focus mode ⚠️ This app ac

Yusuf Özgül 14 Nov 23, 2022
Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.

Easy way to detect device environment: Device model and version Screen resolution Interface orientation iOS version Battery state Environment Helps to

Anatoliy Voropay 582 Dec 25, 2022
A simple utility allowing to detect Swift version at runtime.

SwiftVersionDetector SwiftVersionDetector allows you to detect Swift version at runtime. Note that detecting the Swift version of the machine on which

Alessandro Venturini 2 Dec 3, 2022
Unit-Converter-SwiftUI - A simple Unit Converter iOS app built in the process of learning SwiftUI

SwiftUI-Unit-Converter A simple Unit Converter iOS app built in the process of l

Ishaan Bedi 2 Jul 13, 2022
🟣 Verge is a very tunable state-management engine on iOS App (UIKit / SwiftUI) and built-in ORM.

Verge is giving the power of state-management in muukii/Brightroom v2 development! Verge.swift ?? An effective state management architecture for iOS -

VergeGroup 478 Dec 29, 2022
An OpenAI DALLE2 App - Made with SwiftUI

DALLE2-Swift An OpenAI DALLE2 App - Made with SwiftUI Video Demo https://twitter.com/1998design/status/1582612175021277190?s=61&t=U6jwceFUGJlOkNKAIBbL

MING 9 Dec 20, 2022
A utility that reminds your iPhone app's users to review the app written in pure Swift.

SwiftRater SwiftRater is a class that you can drop into any iPhone app that will help remind your users to review your app on the App Store/in your ap

Takeshi Fujiki 289 Dec 12, 2022
Mac app to change .ipa file app icons and display names

IPAEdit Mac app to change .ipa file app icon, display name, and app version to avoid updates Compatible with macOS 10.11+ Install To install either cl

Ethan Goodhart 23 Dec 28, 2022
A Flutter plugin (platform channel with Swift) to get the current app name and also bring our app to the front.

window_to_front A new flutter plugin project. Getting Started This project is a starting point for a Flutter plug-in package, a specialized package th

Minas Giannekas 1 Nov 13, 2021
A way to easily add Cocoapod licenses and App Version to your iOS App using the Settings Bundle

EasyAbout Requirements: cocoapods version 1.4.0 or above. Why you should use Well, it is always nice to give credit to the ones who helped you ?? Bonu

João Mourato 54 Apr 6, 2022