Ahh this is tedious

This commit is contained in:
Philipp Heckel 2022-05-15 21:08:42 -04:00
parent 7b97c752c0
commit 977f01406c
4 changed files with 18 additions and 5 deletions

View file

@ -23,6 +23,8 @@
9474F1FD2831311A00CDE4DD /* SubscriptionAddView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9474F1FC2831311A00CDE4DD /* SubscriptionAddView.swift */; };
9474F1FF28316ACE00CDE4DD /* Subscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9474F1FE28316ACE00CDE4DD /* Subscription.swift */; };
9474F20128316D1100CDE4DD /* Messenger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9474F20028316D1100CDE4DD /* Messenger.swift */; };
9474F2052831D51500CDE4DD /* Store.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9474F1F82830835400CDE4DD /* Store.swift */; };
9474F2062831D73C00CDE4DD /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 9474F1F52830830700CDE4DD /* Model.xcdatamodeld */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -298,6 +300,8 @@
buildActionMask = 2147483647;
files = (
9474F1E7282F3FFD00CDE4DD /* NotificationService.swift in Sources */,
9474F2052831D51500CDE4DD /* Store.swift in Sources */,
9474F2062831D73C00CDE4DD /* Model.xcdatamodeld in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -12,7 +12,7 @@ import Firebase
@main
struct ntfyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate: AppDelegate
@StateObject private var dataController = Store()
@StateObject private var store = Store()
init() {
FirebaseApp.configure()
@ -21,7 +21,7 @@ struct ntfyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.managedObjectContext, dataController.container.viewContext)
.environment(\.managedObjectContext, store.container.viewContext)
}
}
}

View file

@ -5,6 +5,7 @@ import Firebase
import FirebaseCore
// https://stackoverflow.com/a/41783666/1440785
// https://stackoverflow.com/questions/47374903/viewing-core-data-data-from-your-app-on-a-device
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
@ -22,6 +23,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
registerForPushNotifications()
UNUserNotificationCenter.current().delegate = self
print("Documents Directory: ", FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last ?? "Not Found!")
// Check if launched from notification
let notificationOption = launchOptions?[.remoteNotification]

View file

@ -13,12 +13,15 @@ import CoreData
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
// var store: Store?
var store: Store?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
store = Store()
let context = store?.container.viewContext
print("NotificationService didReceive")
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
@ -30,10 +33,11 @@ class NotificationService: UNNotificationServiceExtension {
let notificationTimestampInt = Int64(notificationTimestamp),
let notificationMessage = userInfo["message"] as? String {
print("notification service \(notificationId)")
/* let notification = Notification(context: context)
/*let notification = Notification()
notification.id = notificationId
notification.time = notificationTimestampInt
notification.message = notificationMessage*/
// try? context?.save()
}
contentHandler(bestAttemptContent)