// // DHBW_ServiceApp.swift // DHBW-Service // // Created by Patrick Müller on 20.12.20. // import SwiftUI import UserNotifications @main struct DHBW_ServiceApp: App { @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate let persistenceController = PersistenceController.shared let settings = LocalSettings() var body: some Scene { WindowGroup { ContentView() .environment(\.managedObjectContext, persistenceController.context) .environmentObject(settings) } } } //*** Implement App delegate ***// class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { return true } //No callback in simulator //-- must use device to get valid push token func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) } let token = tokenParts.joined() print("Device Token: \(token)") } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { print(error.localizedDescription) } }