WIP - a lot of uncommitted work
This commit is contained in:
57
Shared/AppDelegate.swift
Normal file
57
Shared/AppDelegate.swift
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 1/10/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UserNotifications
|
||||
import UIKit
|
||||
import WidgetKit
|
||||
|
||||
// AppDelegate.swift
|
||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
// PersistenceController.shared.clearDB()
|
||||
NotificationCenter.default.addObserver(self,
|
||||
selector: #selector(fetchChanges),
|
||||
name: .NSPersistentStoreRemoteChange,
|
||||
object: PersistenceController.shared.container.persistentStoreCoordinator)
|
||||
|
||||
application.registerForRemoteNotifications()
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
return true
|
||||
}
|
||||
|
||||
@objc func fetchChanges(note: Notification) {
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
}
|
||||
}
|
||||
|
||||
extension AppDelegate: UNUserNotificationCenterDelegate {
|
||||
func requestAuthorization() { }
|
||||
|
||||
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
||||
completionHandler([.badge, .banner, .sound])
|
||||
}
|
||||
|
||||
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
||||
if let action = LocalNotification.ActionType(rawValue: response.actionIdentifier) {
|
||||
switch action {
|
||||
case .horrible:
|
||||
PersistenceController.shared.add(mood: .horrible, forDate: Date())
|
||||
case .bad:
|
||||
PersistenceController.shared.add(mood: .bad, forDate: Date())
|
||||
case .average:
|
||||
PersistenceController.shared.add(mood: .average, forDate: Date())
|
||||
case .good:
|
||||
PersistenceController.shared.add(mood: .good, forDate: Date())
|
||||
case .great:
|
||||
PersistenceController.shared.add(mood: .great, forDate: Date())
|
||||
}
|
||||
}
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
completionHandler()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user