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

35 lines
1.0 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()
.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
}
}
}