From 7b97c752c0036844c8b2dea9d03f4ad20a392e3f Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sun, 15 May 2022 20:17:07 -0400 Subject: [PATCH] App group, this broke something --- Model.xcdatamodeld/Model.xcdatamodel/contents | 18 ++++++++++++++--- ntfy.xcodeproj/project.pbxproj | 4 ++++ ntfy/Messenger.swift | 1 + ntfy/Views/SubscriptionAddView.swift | 2 +- ntfy/ntfy.entitlements | 4 ++++ ntfyNSE/NotificationService.swift | 20 +++++++++++++++++-- ntfyNSE/ntfyNSE.entitlements | 12 +++++++++++ 7 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 ntfyNSE/ntfyNSE.entitlements diff --git a/Model.xcdatamodeld/Model.xcdatamodel/contents b/Model.xcdatamodeld/Model.xcdatamodel/contents index ac6382c..7d8104b 100644 --- a/Model.xcdatamodeld/Model.xcdatamodel/contents +++ b/Model.xcdatamodeld/Model.xcdatamodel/contents @@ -3,16 +3,28 @@ - + - + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/ntfy.xcodeproj/project.pbxproj b/ntfy.xcodeproj/project.pbxproj index a829a39..00323ed 100644 --- a/ntfy.xcodeproj/project.pbxproj +++ b/ntfy.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ 9474F1FC2831311A00CDE4DD /* SubscriptionAddView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionAddView.swift; sourceTree = ""; }; 9474F1FE28316ACE00CDE4DD /* Subscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Subscription.swift; sourceTree = ""; }; 9474F20028316D1100CDE4DD /* Messenger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Messenger.swift; sourceTree = ""; }; + 9474F2042831CDBF00CDE4DD /* ntfyNSE.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ntfyNSE.entitlements; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -145,6 +146,7 @@ 9474F1E5282F3FFD00CDE4DD /* ntfyNSE */ = { isa = PBXGroup; children = ( + 9474F2042831CDBF00CDE4DD /* ntfyNSE.entitlements */, 9474F1E6282F3FFD00CDE4DD /* NotificationService.swift */, 9474F1E8282F3FFD00CDE4DD /* Info.plist */, ); @@ -491,6 +493,7 @@ 9474F1ED282F3FFD00CDE4DD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_ENTITLEMENTS = ntfyNSE/ntfyNSE.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = YXQ4AMS4B4; @@ -517,6 +520,7 @@ 9474F1EE282F3FFD00CDE4DD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_ENTITLEMENTS = ntfyNSE/ntfyNSE.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = YXQ4AMS4B4; diff --git a/ntfy/Messenger.swift b/ntfy/Messenger.swift index 6840ea6..68cfe34 100644 --- a/ntfy/Messenger.swift +++ b/ntfy/Messenger.swift @@ -19,5 +19,6 @@ struct Messenger { subscription.baseUrl = "https://ntfy.sh" subscription.topic = topic try? context.save() + } } diff --git a/ntfy/Views/SubscriptionAddView.swift b/ntfy/Views/SubscriptionAddView.swift index 5c04173..4b1c801 100644 --- a/ntfy/Views/SubscriptionAddView.swift +++ b/ntfy/Views/SubscriptionAddView.swift @@ -52,7 +52,7 @@ struct SubscriptionAddView: View { subscription.baseUrl = "https://ntfy.sh" subscription.topic = topic try? context.save() - + presentationMode.wrappedValue.dismiss() } } diff --git a/ntfy/ntfy.entitlements b/ntfy/ntfy.entitlements index 903def2..384fbad 100644 --- a/ntfy/ntfy.entitlements +++ b/ntfy/ntfy.entitlements @@ -4,5 +4,9 @@ aps-environment development + com.apple.security.application-groups + + group.io.heckel.ntfy + diff --git a/ntfyNSE/NotificationService.swift b/ntfyNSE/NotificationService.swift index f6e56a5..ac0607e 100644 --- a/ntfyNSE/NotificationService.swift +++ b/ntfyNSE/NotificationService.swift @@ -6,20 +6,36 @@ // import UserNotifications +import CoreData + +// https://debashishdas3100.medium.com/save-push-notifications-to-coredata-userdefaults-ios-swift-5-ea074390b57 class NotificationService: UNNotificationServiceExtension { - var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? +// var store: Store? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) - + if let bestAttemptContent = bestAttemptContent { // Modify the notification content here... bestAttemptContent.title = "\(bestAttemptContent.title) [modified]" + let userInfo = bestAttemptContent.userInfo + dump(userInfo) + if let notificationId = userInfo["id"] as? String, + let notificationTimestamp = userInfo["time"] as? String, + let notificationTimestampInt = Int64(notificationTimestamp), + let notificationMessage = userInfo["message"] as? String { + print("notification service \(notificationId)") +/* let notification = Notification(context: context) + notification.id = notificationId + notification.time = notificationTimestampInt + notification.message = notificationMessage*/ + } + contentHandler(bestAttemptContent) } } diff --git a/ntfyNSE/ntfyNSE.entitlements b/ntfyNSE/ntfyNSE.entitlements new file mode 100644 index 0000000..384fbad --- /dev/null +++ b/ntfyNSE/ntfyNSE.entitlements @@ -0,0 +1,12 @@ + + + + + aps-environment + development + com.apple.security.application-groups + + group.io.heckel.ntfy + + +