Custom replacements
To use the custom replacements function yoou will need to update the notification extension cerated in the previous step, here are the steps to follow.

1. Create an app group identifier

Go to developer.apple.com -> Certificates, Identifiers & Profiles -> Identifiers. Select App Groups and create a new one.

2. Enable App Groups

You will need then to enable app groups, with the app group created previously, both on developer.apple.com and on the project in XCode, under the Signing & Capabilities section.
You need to do this for the main app and for the notification extension.

3. Set the app group identifier

In your AppDelegate class set the app group identifier
1
SwiftMpushPlugin.appGroupIdentifier = "YOUR_APP_GROUP_ID"
Copied!

4. Update the notification extension code

Update your notification extension code to manage the replacements
1
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
2
self.contentHandler = contentHandler
3
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
4
5
if let bestAttemptContent = bestAttemptContent {
6
manageCustomReplacements(request: request, bestAttemptContent: bestAttemptContent)
7
...
8
}
9
}
10
​
11
private func manageCustomReplacements(request: UNNotificationRequest, bestAttemptContent: UNMutableNotificationContent) {
12
let appGroupIdentifier = "YOUR_APP_GROUP_ID"
13
let customDatakey = "com.mumble.mpush.customData"
14
guard let customData = UserDefaults(suiteName: appGroupIdentifier)?.object(forKey: customDatakey) as? [String: String] else {
15
return
16
}
17
18
for (key, value) in customData {
19
bestAttemptContent.title = request.content.title.replacingOccurrences(of: key, with: value)
20
bestAttemptContent.body = request.content.body.replacingOccurrences(of: key, with: value)
21
}
22
}
Copied!