App group, this broke something

This commit is contained in:
Philipp Heckel 2022-05-15 20:17:07 -04:00
parent 7def871bfe
commit 7b97c752c0
7 changed files with 55 additions and 6 deletions

View file

@ -3,16 +3,28 @@
<entity name="Notification" representedClassName="Notification" parentEntity="Subscription" syncable="YES" codeGenerationType="class">
<attribute name="id" attributeType="String"/>
<attribute name="message" attributeType="String"/>
<attribute name="timestamp" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="time" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="title" optional="YES" attributeType="String"/>
<relationship name="subscription" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Subscription"/>
<relationship name="subscription" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Subscription" inverseName="notifications" inverseEntity="Subscription"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="Subscription" representedClassName="Subscription" syncable="YES" codeGenerationType="class">
<attribute name="baseUrl" attributeType="String"/>
<attribute name="topic" attributeType="String" minValueString="1" maxValueString="64" regularExpressionString="^[-_A-Za-z0-9]{1,64}$"/>
<relationship name="notifications" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Notification" inverseName="subscription" inverseEntity="Notification"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="baseUrl"/>
<constraint value="topic"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<elements>
<element name="Subscription" positionX="-63" positionY="-18" width="128" height="59"/>
<element name="Subscription" positionX="-63" positionY="-18" width="128" height="74"/>
<element name="Notification" positionX="-54" positionY="9" width="128" height="104"/>
</elements>
</model>

View file

@ -69,6 +69,7 @@
9474F1FC2831311A00CDE4DD /* SubscriptionAddView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionAddView.swift; sourceTree = "<group>"; };
9474F1FE28316ACE00CDE4DD /* Subscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Subscription.swift; sourceTree = "<group>"; };
9474F20028316D1100CDE4DD /* Messenger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Messenger.swift; sourceTree = "<group>"; };
9474F2042831CDBF00CDE4DD /* ntfyNSE.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ntfyNSE.entitlements; sourceTree = "<group>"; };
/* 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;

View file

@ -19,5 +19,6 @@ struct Messenger {
subscription.baseUrl = "https://ntfy.sh"
subscription.topic = topic
try? context.save()
}
}

View file

@ -52,7 +52,7 @@ struct SubscriptionAddView: View {
subscription.baseUrl = "https://ntfy.sh"
subscription.topic = topic
try? context.save()
presentationMode.wrappedValue.dismiss()
}
}

View file

@ -4,5 +4,9 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.io.heckel.ntfy</string>
</array>
</dict>
</plist>

View file

@ -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)
}
}

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.io.heckel.ntfy</string>
</array>
</dict>
</plist>