I moved things to a Push directory, so to see the diff, look at the 2nd commit (or 3rd for the tests).
The ParsedNotification struct takes all the expected keys from the push payload and fails otherwise. This validates the push is an Appcues one and gives us typed data to work with.
I added a push experience trigger instead of reusing an existing one.
I'm using the experience Actions primarily for code reuse (in particular the link actions handles delegates and universal links, and copy/pasting that doesn't make sense).
I'm not sure about the handling around sessions and user ID matching, but I've done what we discussed and adde tests for it.
There's also an async version of the UNUserNotificationCenterDelegate method: func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async, so we might want to add our own async handler (using withCheckedContinuation) for a better developer experience.
Usage
extension AppDelegate: UNUserNotificationCenterDelegate {
// Asks the delegate to process the user's response to a delivered notification.
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
if Appcues.shared.didReceiveNotification(response: response, completionHandler: completionHandler) {
return
}
// Manually call completionHandler, because Appcues won't if it doesn't handle the notification
completionHandler()
}
}
Notes
Push
directory, so to see the diff, look at the 2nd commit (or 3rd for the tests).ParsedNotification
struct takes all the expected keys from the push payload and fails otherwise. This validates the push is an Appcues one and gives us typed data to work with.UNUserNotificationCenterDelegate
method:func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async
, so we might want to add our own async handler (usingwithCheckedContinuation
) for a better developer experience.Usage
Also [sc-61014]