pushdeer/ios/PushDeer-iOS/PushDeer/PushDeerApp.swift

47 lines
1.5 KiB
Swift
Raw Normal View History

2021-12-27 22:33:27 +08:00
//
// PushDeerApp.swift
// PushDeer
//
// Created by HEXT on 2021/12/25.
//
import SwiftUI
@main
struct PushDeerApp: App {
2022-01-04 22:28:18 +08:00
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
let store = AppState.shared
let persistenceController = PersistenceController.shared
2022-01-04 22:28:18 +08:00
2021-12-27 22:33:27 +08:00
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL(perform: { url in
print(#function, url)
#if !targetEnvironment(macCatalyst) && !APPCLIP && !SELFHOSTED
WXApi.handleOpen(url, delegate: WXDelegate.shared)
#endif
})
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb, perform: { userActivity in
print(#function, userActivity.webpageURL as Any)
#if !targetEnvironment(macCatalyst) && !APPCLIP && !SELFHOSTED
WXApi.handleOpenUniversalLink(userActivity, delegate: WXDelegate.shared)
#endif
})
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
// ,
UIApplication.shared.applicationIconBadgeNumber = 0
// ,
if !AppState.shared.token.isEmpty {
Task {
let messageItems = try await HttpRequest.getMessages().messages
try MessageModel.saveAndUpdate(messageItems: messageItems)
}
}
}
.environmentObject(store)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
2021-12-27 22:33:27 +08:00
}
}
}