-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'test-out-xcode-161rc-ios-902'
- Loading branch information
Showing
20 changed files
with
162 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// BackgroundTaskProvider.swift | ||
// MullvadVPN | ||
// | ||
// Created by Marco Nikic on 2023-10-02. | ||
// Copyright © 2023 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
#if canImport(UIKit) | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
@available(iOSApplicationExtension, unavailable) | ||
public protocol BackgroundTaskProviding { | ||
var backgroundTimeRemaining: TimeInterval { get } | ||
#if compiler(>=6) | ||
nonisolated | ||
func beginBackgroundTask( | ||
withName taskName: String?, | ||
expirationHandler handler: (@MainActor @Sendable () -> Void)? | ||
) -> UIBackgroundTaskIdentifier | ||
#else | ||
func beginBackgroundTask( | ||
withName taskName: String?, | ||
expirationHandler handler: (() -> Void)? | ||
) -> UIBackgroundTaskIdentifier | ||
#endif | ||
|
||
func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier) | ||
} | ||
|
||
@available(iOSApplicationExtension, unavailable) | ||
public class BackgroundTaskProvider: BackgroundTaskProviding { | ||
public var backgroundTimeRemaining: TimeInterval | ||
weak var application: UIApplication! | ||
|
||
public init(backgroundTimeRemaining: TimeInterval, application: UIApplication) { | ||
self.backgroundTimeRemaining = backgroundTimeRemaining | ||
self.application = application | ||
} | ||
|
||
#if compiler(>=6) | ||
nonisolated | ||
public func beginBackgroundTask( | ||
withName taskName: String?, | ||
expirationHandler handler: (@MainActor @Sendable () -> Void)? | ||
) -> UIBackgroundTaskIdentifier { | ||
application.beginBackgroundTask(withName: taskName, expirationHandler: handler) | ||
} | ||
#else | ||
public func beginBackgroundTask( | ||
withName taskName: String?, | ||
expirationHandler handler: (() -> Void)? | ||
) -> UIBackgroundTaskIdentifier { | ||
application.beginBackgroundTask(withName: taskName, expirationHandler: handler) | ||
} | ||
#endif | ||
|
||
public func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier) { | ||
application.endBackgroundTask(identifier) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.