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

52 lines
1.8 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
import WidgetKit
2021-12-27 22:33:27 +08:00
@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)
}
}
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification), perform: { _ in
// APP,
WidgetCenter.shared.reloadAllTimelines()
})
.environmentObject(store)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
2021-12-27 22:33:27 +08:00
}
}
}