iOS notifications actions without opening the app

5.9k Views Asked by At

Is there a way to intercept user's click on push notification or user's click on rich push notification action button, WITHOUT LAUNCHING THE APP? I have implemented all necessary settings to register for push notifications, to receive push notifications and to handle simple and rich push notifications, and user's click on some action button inside rich push notification. But, when user clicks on some action button, app launches, and I can handle it inside:

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    let notification = JSONParser.parseRichPushNotification(notification: response.notification.request.content.userInfo)
    if let responseIdentifier = 
    {
         print(response.actionIdentifier)
    }
//......
}

I would like to perform, for example some background action without launching the app, or to open web browser if there is a link in push notification data. Is it that possible in iOS?

I have found similar questions:

But I think that I didn't find the answer for my question. I have also read about silent notifications, but I am not sure if I can use them for this purpose, i.e. to perform some operation when user clicks on action button without automatic launching the app.

Btw, I'm usine OneSignal push notifications

Does anybody know how to perform this? Thanks in advance

1

There are 1 best solutions below

1
Antonio R. On

You can accomplish this by creating a Custom Interface that implements the UINotificationContentExtension protocol.