appcues / appcues-ios-sdk

The Appcues iOS SDK
https://www.appcues.com/mobile
MIT License
8 stars 2 forks source link

Add push response handler #510

Closed mmaatttt closed 6 months ago

mmaatttt commented 6 months ago

Notes

  1. I moved things to a Push directory, so to see the diff, look at the 2nd commit (or 3rd for the tests).
  2. 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.
  3. I added a push experience trigger instead of reusing an existing one.
  4. 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).
  5. 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.
  6. 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()
    }
}

Also [sc-61014]

shortcut-integration[bot] commented 6 months ago

This pull request has been linked to: