iOS notifications actions without opening the app

你离开我真会死。 提交于 2019-12-14 02:22:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!