diff --git a/NotificationServiceExtension/Info.plist b/NotificationServiceExtension/Info.plist new file mode 100644 index 0000000..3c15496 --- /dev/null +++ b/NotificationServiceExtension/Info.plist @@ -0,0 +1,31 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Notification Service Extension + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionPointIdentifier + com.apple.usernotifications.service + NSExtensionPrincipalClass + $(PRODUCT_MODULE_NAME).NotificationService + + + diff --git a/NotificationServiceExtension/NotificationService.swift b/NotificationServiceExtension/NotificationService.swift new file mode 100644 index 0000000..443bc80 --- /dev/null +++ b/NotificationServiceExtension/NotificationService.swift @@ -0,0 +1,23 @@ +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 { + bestAttemptContent.title = "\(bestAttemptContent.title) [modified]" + contentHandler(bestAttemptContent) + } + } + + override func serviceExtensionTimeWillExpire() { + if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { + contentHandler(bestAttemptContent) + } + } +} diff --git a/Project/Targets/NotificationServiceExtension.yml b/Project/Targets/NotificationServiceExtension.yml new file mode 100644 index 0000000..6ead930 --- /dev/null +++ b/Project/Targets/NotificationServiceExtension.yml @@ -0,0 +1,8 @@ +targets: + NotificationServiceExtension: + platform: iOS + type: app-extension + sources: + - NotificationServiceExtension + dependencies: + - target: XcodeGen \ No newline at end of file diff --git a/Project/targets.yml b/Project/targets.yml index 656116c..fd295e4 100644 --- a/Project/targets.yml +++ b/Project/targets.yml @@ -1,4 +1,5 @@ include: - Targets/XcodeGen.yml - Targets/XcodeGenTests.yml - - Targets/XcodeGenUITests.yml \ No newline at end of file + - Targets/XcodeGenUITests.yml + - Targets/NotificationServiceExtension.yml \ No newline at end of file diff --git a/README.md b/README.md index 61de416..933e492 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ # XcodeGen -### Step 7 -All we have done at this step is to organise our `.yml` file so it's easier to reason and code review. +### Step 8 +We have now added a new Notification Service Extension tarted to the app by simply adding 9 short lines across two `.yml` files. + +It is now a lot easier to code review the settings and what the change will bring. --- ### Next -Please now checkout `step-8` +Please now checkout `step-9` -`git checkout tags/step-8` +`git checkout tags/step-9` ---