So, my backend is sending push notifications, for example like this:
$data = array(
"notification" => array(
"title" => $title,
"body" => $message,
"sound" => true,
"badge" => "1"
),
"to" => $tok,
"content_available"=>true
);
$data['data'] = array(
"type"=>"foo"
);
If I receive a notification when the app is open, I can inspect the contents of data and do something, like offer to bring the user to foo page. But, if the user receives the typical iOS notification because the app is in the background, when the user opens the app by tapping the notification, it just opens the app. Theres no way I can see to inspect data to bring them to the appropriate page based on the data. Is this possible?
It should be turning up the in UNNotificationResponse object in the didReceiveNotificationResponse callback.
I just managed to get it working by implementing this method of the UNUserNotificationCenterDelegate (iOS 10).
This gets called when the user taps on the notification and the app opens. I believe this is documented, but the documentation seems to be confusing a few people.
```@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
log.debug("userNotificationCenter didReceive")
let userInfo = response.notification.request.content.userInfo
self.notificationHandler?.handleNotification(payload: userInfo)
}
Closing this issue since it is solved.
Most helpful comment
I just managed to get it working by implementing this method of the UNUserNotificationCenterDelegate (iOS 10).
This gets called when the user taps on the notification and the app opens. I believe this is documented, but the documentation seems to be confusing a few people.
```@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
log.debug("userNotificationCenter didReceive")
let userInfo = response.notification.request.content.userInfo
self.notificationHandler?.handleNotification(payload: userInfo)
}