引入进程级 CameraTetheringSession 与共享 USB Browser;离开传图页仅取消 UI 回调,App 终止时再完整 shutdown 释放 PTP 与 Browser 资源。 Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.5 KiB
Swift
51 lines
1.5 KiB
Swift
//
|
||
// AppDelegate.swift
|
||
// suixinkan
|
||
//
|
||
// Created by Codex on 2026/6/26.
|
||
//
|
||
|
||
import UIKit
|
||
|
||
/// AppDelegate 承接 APNs 系统回调,SwiftUI App 入口通过 adaptor 注入。
|
||
final class AppDelegate: NSObject, UIApplicationDelegate {
|
||
func application(
|
||
_ application: UIApplication,
|
||
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
|
||
) {
|
||
Task { @MainActor in
|
||
PushNotificationManager.shared.handleDeviceToken(deviceToken)
|
||
}
|
||
}
|
||
|
||
func application(
|
||
_ application: UIApplication,
|
||
didFailToRegisterForRemoteNotificationsWithError error: Error
|
||
) {
|
||
Task { @MainActor in
|
||
PushNotificationManager.shared.handleRegistrationError(error)
|
||
}
|
||
}
|
||
|
||
func application(
|
||
_ application: UIApplication,
|
||
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
|
||
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
|
||
) {
|
||
let payload = PushPayload(userInfo: userInfo)
|
||
Task { @MainActor in
|
||
PushNotificationManager.shared.handleRemoteNotification(payload)
|
||
completionHandler(.newData)
|
||
}
|
||
}
|
||
|
||
func applicationWillTerminate(_ application: UIApplication) {
|
||
let semaphore = DispatchSemaphore(value: 0)
|
||
Task { @MainActor in
|
||
await CameraTetheringSession.shutdown()
|
||
semaphore.signal()
|
||
}
|
||
_ = semaphore.wait(timeout: .now() + 2)
|
||
}
|
||
}
|