Maintini

1.0.6

A friendly and efficient wrapper to protect iOS app operations for a short time when backgrounded.
ptsochantaris/maintini

What's New

Version 1.0.6

2023-10-06T15:03:02Z
  • Simplified conditional directives, so that building for visionOS now works as well

Logo

Maintini

A friendly and efficient wrapper for wrapping operations so that:

  • iOS: Keep the app active for a short time when backgrounded.
  • macOS: Ask the system not to go into idle sleep if possible.

Currently used in

Detailed docs can be found here

Overview

  • Calls can be nested around any critical section, and Maintini only calls out to the OS task APIs if needed, so these calls are very cheap.
  • Maintini will keep the OS from suspending the app, or sleeping, as long as possible if there is at least one session present.
  • If the last session exits on iOS, and the app is in the background, it will be suspended a couple of seconds later.
  • iOS places a hard limit on the amount of time allowed, and the app will be suspended at the end of that period no matter what. Completing API calls, short data transfers, or sync operations are the kind of thing Maintini is designed for. For longer running operations please refer to Apple's Background Task scheduling API instead.
Maintini.setup() // Always call this at app launch to set things up
...

func anExampleWithABlockCall() async {
    await Maintini.maintain {
        await processingThatShouldNotBeInterrupted()
    }
}

func anExampleWithADeferredCall() async {
    Maintini.startMaintaining()
    defer {
        Maintini.endMaintaining()
    }
    await processingThatShouldNotBeInterrupted()
}

func anExampleWithNestedCalls() async {
    Maintini.startMaintaining()

    Task {
        await processingThatShouldNotBeInterrupted()

        await anExampleWithADeferredCall()

        await anExampleWithABlockCall()

        Maintini.endMaintaining()
    }
}

License

Copyright (c) 2023 Paul Tsochantaris. Licensed under the MIT License, see LICENSE for details.

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 19:45:49 GMT-0900 (Hawaii-Aleutian Daylight Time)