Files
comaps/iphone/Maps/OMapsWidgetExtension/LiveActivity/LiveActivityManager.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

27 lines
816 B
Swift

import ActivityKit
import SwiftUI
@available(iOS 16.2, *)
final class LiveActivityManager {
static func startActivity<T: ActivityAttributes>(_ attributes: T, content: ActivityContent<T.ContentState>) throws -> Activity<T> {
return try Activity.request(attributes: attributes, content: content, pushType: nil)
}
static func update<T: ActivityAttributes>(_ activity: Activity<T>, content: ActivityContent<T.ContentState>) {
Task {
await activity.update(content)
}
}
static func stop(_ activity: Activity<some ActivityAttributes>) {
// semaphore is used for removing the activity during the app termination
let semaphore = DispatchSemaphore(value: 0)
Task {
await activity.end(nil, dismissalPolicy: .immediate)
semaphore.signal()
}
semaphore.wait()
}
}