无需打开应用程序的 iOS 通知操作 [英] iOS notifications actions without opening the app

查看:45
本文介绍了无需打开应用程序的 iOS 通知操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在不启动应用程序的情况下拦截用户点击推送通知或用户点击富推送通知操作按钮?我已经实现了所有必要的设置来注册推送通知、接收推送通知和处理简单和丰富的推送通知,以及用户点击富推送通知中的某个操作按钮.但是,当用户点击某个操作按钮时,应用程序就会启动,我可以在里面处理它:

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)
    }
//......
}

我想在不启动应用程序的情况下执行某些后台操作,或者在推送通知数据中有链接时打开网络浏览器.在 iOS 中可以吗?

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?

我发现了类似的问题:

但我认为我没有找到我的问题的答案.我还阅读了有关静默通知的内容,但我不确定是否可以将它们用于此目的,即在用户单击操作按钮时执行某些操作而不自动启动应用程序.

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.

顺便说一句,我正在使用 OneSignal 推送通知

Btw, I'm usine OneSignal push notifications

有人知道如何执行此操作吗?提前致谢

Does anybody know how to perform this? Thanks in advance

推荐答案

您可以通过创建一个 自定义界面,实现了UINotificationContentExtension 协议.

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

这篇关于无需打开应用程序的 iOS 通知操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆