teachers-assistant

[RADIOACTIVE] oh boy did i make bad apps back in the day
git clone git://git.figbert.com/teachers-assistant.git
Log | Files | Refs

AppDelegate.swift (3590B)


      1 //
      2 //  AppDelegate.swift
      3 //  Teachers' Assistant
      4 //
      5 //  Created by Benjamin Welner on 2/9/19.
      6 //  Copyright © 2019 FIGBERT Inc. All rights reserved.
      7 //
      8 
      9 import UIKit
     10 import UserNotifications
     11 
     12 @UIApplicationMain
     13 class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
     14     
     15     var window: UIWindow?
     16 
     17     func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
     18         completionHandler([.alert, .badge, .sound])
     19     }
     20     
     21     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     22         
     23         //Notification permission request
     24         UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound])  { (granted, error) in}
     25         UNUserNotificationCenter.current().delegate = self
     26         
     27         /* FIRST TIME RUN CODE START */
     28         let hasLaunchedKey = "HasLaunched"
     29         let defaults = UserDefaults.standard
     30         let hasLaunched = defaults.bool(forKey: hasLaunchedKey)
     31         
     32         let welcomeNotification = UNMutableNotificationContent()
     33         welcomeNotification.title = "Welcome"
     34         welcomeNotification.body = "Enjoy the app!"
     35         welcomeNotification.sound = UNNotificationSound.default
     36         let welcomeTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
     37         let welcomePing = UNNotificationRequest(identifier: "welcomePing", content: welcomeNotification, trigger: welcomeTrigger)
     38         UNUserNotificationCenter.current().add(welcomePing, withCompletionHandler: nil)
     39         
     40         if !hasLaunched {
     41             defaults.set(true, forKey: hasLaunchedKey)
     42         }
     43         
     44         /* FIRST TIME RUN CODE END */
     45         
     46         return true
     47     }
     48 
     49     func applicationWillResignActive(_ application: UIApplication) {
     50         // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     51         // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
     52     }
     53 
     54     func applicationDidEnterBackground(_ application: UIApplication) {
     55         // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
     56         // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     57     }
     58 
     59     func applicationWillEnterForeground(_ application: UIApplication) {
     60         // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
     61     }
     62 
     63     func applicationDidBecomeActive(_ application: UIApplication) {
     64         // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     65     }
     66 
     67     func applicationWillTerminate(_ application: UIApplication) {
     68         // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
     69     }
     70 
     71 
     72 }
     73