diff options
author | Ivan Sein <ivan@nextcloud.com> | 2020-01-30 11:42:41 +0300 |
---|---|---|
committer | Ivan Sein <ivan@nextcloud.com> | 2020-01-31 12:53:32 +0300 |
commit | b67358d91f9b945373338787cc03f5ce9631b658 (patch) | |
tree | 99240d147eaf454219a3225eff85b4b941580969 /Notification Service Extension | |
parent | 7bf6e366c4f63bbe6b47dcadae4e964b784af9c5 (diff) |
Add Notification Service Extension.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
Diffstat (limited to 'Notification Service Extension')
4 files changed, 116 insertions, 0 deletions
diff --git a/Notification Service Extension/Info.plist b/Notification Service Extension/Info.plist new file mode 100644 index 000000000..73937693f --- /dev/null +++ b/Notification Service Extension/Info.plist @@ -0,0 +1,31 @@ +<?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>CFBundleDevelopmentRegion</key> + <string>$(DEVELOPMENT_LANGUAGE)</string> + <key>CFBundleDisplayName</key> + <string>Notification Service Extension</string> + <key>CFBundleExecutable</key> + <string>$(EXECUTABLE_NAME)</string> + <key>CFBundleIdentifier</key> + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>$(PRODUCT_NAME)</string> + <key>CFBundlePackageType</key> + <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + <key>NSExtension</key> + <dict> + <key>NSExtensionPointIdentifier</key> + <string>com.apple.usernotifications.service</string> + <key>NSExtensionPrincipalClass</key> + <string>$(PRODUCT_MODULE_NAME).NotificationService</string> + </dict> +</dict> +</plist> diff --git a/Notification Service Extension/Notification Service Extension.entitlements b/Notification Service Extension/Notification Service Extension.entitlements new file mode 100644 index 000000000..4ecc3f0d1 --- /dev/null +++ b/Notification Service Extension/Notification Service Extension.entitlements @@ -0,0 +1,14 @@ +<?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>com.apple.security.application-groups</key> + <array> + <string>group.it.twsweb.Crypto-Cloud</string> + </array> + <key>keychain-access-groups</key> + <array> + <string>$(AppIdentifierPrefix)it.twsweb.Crypto-Cloud</string> + </array> +</dict> +</plist> diff --git a/Notification Service Extension/NotificationService.swift b/Notification Service Extension/NotificationService.swift new file mode 100644 index 000000000..fb36031c5 --- /dev/null +++ b/Notification Service Extension/NotificationService.swift @@ -0,0 +1,49 @@ +// +// NotificationService.swift +// Notification Service Extension +// +// Created by Ivan Sein on 30.01.20. +// Author Ivan Sein <ivan@nextcloud.com> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +import UserNotifications + +class NotificationService: UNNotificationServiceExtension { + + var contentHandler: ((UNNotificationContent) -> Void)? + var bestAttemptContent: UNMutableNotificationContent? + + 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]" + + contentHandler(bestAttemptContent) + } + } + + override func serviceExtensionTimeWillExpire() { + // Called just before the extension will be terminated by the system. + // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. + if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { + contentHandler(bestAttemptContent) + } + } + +} diff --git a/Notification Service Extension/Notification_Service_Extension-Bridging-Header.h b/Notification Service Extension/Notification_Service_Extension-Bridging-Header.h new file mode 100644 index 000000000..1ea3b5805 --- /dev/null +++ b/Notification Service Extension/Notification_Service_Extension-Bridging-Header.h @@ -0,0 +1,22 @@ +// +// Notification_Service_Extension-Bridging-Header.h +// Nextcloud +// +// Created by Ivan Sein on 30.01.20. +// Author Ivan Sein <ivan@nextcloud.com> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + + |