// // AppDelegate.swift // Need-to-pump-up // // Created by Дмитрий Собин on 13.07.2020. // Copyright © 2020 Дмитрий Собин. All rights reserved. // import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. Model.shared.loadPrograms() let db: DBHelper = DBHelper() // check first run app. If true — init env. if false — let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore") if launchedBefore { print("Not first launch.") UNUserNotificationCenter.current() .requestAuthorization( options: [.alert, .sound, .badge]) { [weak self] granted, _ in print("Permission granted: \(granted)") guard granted else { return } // self?.getNotificationSettings() } } else { print("First launch, setting UserDefault.") db.initEnvTable() UserDefaults.standard.set(true, forKey: "launchedBefore") } Model.shared.allProg = [] Model.shared.allProg.append(db.selectProgram(idProgram: 1)!) print(Model.shared.allProg[0].name) Model.shared.allProg.append(db.selectProgram(idProgram: 2)!) print(Model.shared.allProg[1].name) Model.shared.allProg.append(db.selectProgram(idProgram: 3)!) print(Model.shared.allProg[2].name) Model.shared.allProg.append(db.selectProgram(idProgram: 4)!) print(Model.shared.allProg[3].name) UNUserNotificationCenter.current().delegate = self //testSection // db.selectNextProgram(idProgram: 1, idLevel: 1, idDay: 2) return true } func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo print(userInfo) // the payload that is attached to the push notification // you can customize the notification presentation options. Below code will show notification banner as well as play a sound. If you want to add a badge too, add .badge in the array. completionHandler([.alert, .sound]) } // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } }