问题
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:
- Is there a way to open urls received in a push notification without opening the app in ios 10?
- Handle Push Notification when the App is off, or without opening the App at all - iOS
- Android notifications actions without opening the app
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:
You can accomplish this by creating a Custom Interface that implements the UINotificationContentExtension protocol.
来源:https://stackoverflow.com/questions/43214993/ios-notifications-actions-without-opening-the-app