Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions NotificationServiceExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -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>XPC!</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>
23 changes: 23 additions & 0 deletions NotificationServiceExtension/NotificationService.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
8 changes: 8 additions & 0 deletions Project/Targets/NotificationServiceExtension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
targets:
NotificationServiceExtension:
platform: iOS
type: app-extension
sources:
- NotificationServiceExtension
dependencies:
- target: XcodeGen
3 changes: 2 additions & 1 deletion Project/targets.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include:
- Targets/XcodeGen.yml
- Targets/XcodeGenTests.yml
- Targets/XcodeGenUITests.yml
- Targets/XcodeGenUITests.yml
- Targets/NotificationServiceExtension.yml
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`

---

Expand Down