SPB Git

Repository Public

LocalChatIOSApp.swift 1.3 KB 32 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Apps/LocalChatIOS/LocalChatIOSApp.swift3// Description: Local Chat for iPhone and iPad: one adaptive scene, background download completion, memory-warning handling.4import SwiftUI5import UIKit6import LocalChatCore7import LocalChatUI89@main10struct LocalChatIOSApp: App {11    @UIApplicationDelegateAdaptor(IOSAppDelegate.self) private var delegate12    @State private var app = AppBootstrap.make()1314    var body: some Scene {15        WindowGroup {16            AppBootstrap.root(app)17                .onReceive(NotificationCenter.default.publisher(for: UIApplication.didReceiveMemoryWarningNotification)) { _ in18                    // iOS is about to kill the app: release every model that is not generating19                    Task { await app.model?.engine.unloadIdle(olderThan: 0) }20                }21        }22    }23}2425final class IOSAppDelegate: NSObject, UIApplicationDelegate {26    /// Background URLSession events (model downloads that finished while the app was suspended).27    nonisolated(unsafe) static var backgroundCompletion: (() -> Void)?28    func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {29        Self.backgroundCompletion = completionHandler30    }31}32
Files main
Menu

Theme