Signal-iOS/SignalServiceKit/Util/AVAssetExportSession+Async.swift
Adam Sharp f8bcb88467
Work around AVAssetExportSession.export(to:as:) not being back-deployed
In Xcode 16 beta 4, this API was marked as back-deployed before iOS 18, but
that changed in beta 5. Because calling the older export() API now generates a
(possibly spurious) warning about the export session leaving its isolation,
introduce a wrapper that's available before iOS 18 and uses the proper
isolation.
2024-08-12 20:49:08 -04:00

33 lines
1.1 KiB
Swift

//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import AVFoundation
extension AVAssetExportSession {
#if compiler(>=6.0)
/// Workaround for `export(to:as:)` not being back-deployed before iOS 18.
@available(iOSApplicationExtension, obsoleted: 18.0, message: "Use export(to:as:) instead")
@inlinable
public func exportAsync(to url: URL, as fileType: AVFileType, isolation: isolated (any Actor)? = #isolation) async throws {
if #available(iOSApplicationExtension 18.0, *) {
try await export(to: url, as: fileType)
} else {
outputURL = url
outputFileType = fileType
return try await withCheckedThrowingContinuation { continuation in
nonisolated(unsafe) let session = self
exportAsynchronously {
if session.status == .cancelled {
continuation.resume(throwing: CancellationError())
} else {
continuation.resume()
}
}
}
}
}
#endif
}