Notification Interactions
Handling all notification interactions
class AppDelegate: NSObject, UIApplicationDelegate {
static var bird: Bird!
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AppDelegate")
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
do {
Self.bird = try Bird()
} catch {
Self.logger.info("failed to create bird \(error)")
}
// Set UNUserNotificationCenterDelegate
UNUserNotificationCenter.current().delegate = self
return true
}
// Other methods of UIApplicationDelegate
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
// All notification interactions are captured here
if let result = Self.bird.notifications.handleNotificationResponse(
response: response,
// Set automaticallyOpenDeeplinks to true if you want deep links
// to be automatically opened
automaticallyOpenDeeplinks: false
) {
// The result contains the url and the custom payload
Self.logger.log("type \(result.type.rawValue)")
Self.logger.log("payload \(result.payload))")
Self.logger.log("action.type \(result.action.type.rawValue)")
Self.logger.log("action.url \(result.action.url?.absoluteString ?? "")")
Self.logger.log("action.identifier \(result.action.identifier)")
}
completionHandler()
}
// Other methods of UNUserNotificationCenterDelegate
}
Deep Links
Custom Payload
Last updated
Was this helpful?

