【发布时间】:2018-12-10 13:33:22
【问题描述】:
当应用处于后台状态时,我必须启动两个不同的实验,
- 当通知到达用户但尚未点击时。 (这个没有实现)
- 在所有通知中,用户点击通知的次数 警报和打开应用程序。 (这是实现的)
我使用了以下方法: 当用户通过点击警报消息来响应通知时,系统会调用以下方法并返回结果。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
如果您的应用在前台并且有通知到达,通知中心会调用以下方法将通知直接发送到您的应用。
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
【问题讨论】:
-
尝试静默推送来满足此类需求。 stackoverflow.com/questions/36694963/…
-
无声推送不是必需的,因为企业希望用户在每次推送时都采取行动,并且希望在一个用户选择并点击的所有通知中计数。
-
静默推送后,您可以生成本地通知,告知哪些用户点击了,您将获得点击次数。
标签: ios swift push-notification nsusernotificationcenter