One of the test cases in our Integration Testing Guide covers tapping received push notifications when the app is not actively running in the background. If that test fails for your iOS application, and the intended URL is not properly opened as expected, this guide can be used to help correct that behavior.
In the part of your app where you are handling receiving notifications, make sure you are including the application:didReceiveRemoteNotification:fetchCompletionHandler: Apple method in your code. This method will trigger even if the app is in a killed state and will allow it to process the notification so it can bring the user to the correct URL destination.
For more information about how iOS notifications work consult Apple’s development notes regarding Handling Notifications.
Here is a basic example of some sample code employing this pattern:
open func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
NSLog("didReceiveRemoteNotification called")
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
guard (userInfo["aps"] as? [String: AnyObject]) != nil else {
completionHandler(.failed)
return
}
guard (userInfo["isNudge"] as? Bool) != nil else {
return
}
let isNudge = userInfo["isNudge"] as! Bool;
if (isNudge) {
NudgeBase.receivedPush(notificationPayload:userInfo, application: application)
}
completionHandler(.noData)
}
Comments
0 comments
Article is closed for comments.