mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Fix state machine crashes & background tasks (#343)
* Fix `UIApplication.shared` after moving to SwiftUI app * Do not autoplay videos on background * Move app state changes into the app coordinator * Add application background task, move into the suspended state more accurately * Add changelog * Fix most of the linter errors * Strip suspended state from state machine * Fix build * Clear audio session warning * Update AppCoordinator.swift * Update AppCoordinator.swift * Swift format
This commit is contained in:
@@ -53,6 +53,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
|
||||
// attempt to start
|
||||
identifier = application.beginBackgroundTask(withName: name) { [weak self] in
|
||||
guard let self else { return }
|
||||
self.stop()
|
||||
self.expirationHandler?(self)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,17 @@ import UIKit
|
||||
|
||||
/// /// UIKitBackgroundTaskService is a concrete implementation of BackgroundTaskServiceProtocol using a given `ApplicationProtocol` instance.
|
||||
class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol {
|
||||
private let application: ApplicationProtocol?
|
||||
private let applicationBlock: () -> ApplicationProtocol?
|
||||
private var reusableTasks: WeakDictionary<String, UIKitBackgroundTask> = WeakDictionary()
|
||||
|
||||
private var application: ApplicationProtocol? {
|
||||
applicationBlock()
|
||||
}
|
||||
|
||||
/// Initializer
|
||||
/// - Parameter application: application instance to use. Defaults to `UIApplication.extensionSafeShared`.
|
||||
init(withApplication application: ApplicationProtocol? = UIApplication.extensionSafeShared) {
|
||||
self.application = application
|
||||
/// - Parameter applicationBlock: block returning the application instance to use. Defaults to a block returning `UIApplication.extensionSafeShared`.
|
||||
init(withApplicationBlock applicationBlock: @escaping () -> ApplicationProtocol? = { UIApplication.extensionSafeShared }) {
|
||||
self.applicationBlock = applicationBlock
|
||||
}
|
||||
|
||||
func startBackgroundTask(withName name: String,
|
||||
|
||||
Reference in New Issue
Block a user