Вот что у меня есть:
appApp.swift
Код: Выделить всё
@main
struct appApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@State private var notificationStatus: String = "na"
var body: some Scene {
WindowGroup {
if appDelegate.notificationStatus == true {
NotificationView()
} else {
ContentView()
}
}
}
}
Код: Выделить всё
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
@Published var notificationStatus: Bool = false
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let center = UNUserNotificationCenter.current()
center.getNotificationSettings { settings in
switch settings.authorizationStatus {
case .notDetermined:
self.notificationStatus = false
case .denied:
self.notificationStatus = false
case .authorized:
self.notificationStatus = true
case .provisional:
self.notificationStatus = true
case .ephemeral:
self.notificationStatus = false
@unknown default:
self.notificationStatus = false
}
}
return true
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... ppdelegate
Мобильная версия