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.
Go to developer.apple.com -> Certificates, Identifiers & Profiles -> Identifiers. Select App Groups and create a new one.

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.
In your
AppDelegate
class set the app group identifierSwiftMpushPlugin.appGroupIdentifier = "YOUR_APP_GROUP_ID"
Update your notification extension code to manage the replacements
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
manageCustomReplacements(request: request, bestAttemptContent: bestAttemptContent)
...
}
}
private func manageCustomReplacements(request: UNNotificationRequest, bestAttemptContent: UNMutableNotificationContent) {
let appGroupIdentifier = "YOUR_APP_GROUP_ID"
let customDatakey = "com.mumble.mpush.customData"
guard let customData = UserDefaults(suiteName: appGroupIdentifier)?.object(forKey: customDatakey) as? [String: String] else {
return
}
for (key, value) in customData {
bestAttemptContent.title = request.content.title.replacingOccurrences(of: key, with: value)
bestAttemptContent.body = request.content.body.replacingOccurrences(of: key, with: value)
}
}
Last modified 1yr ago