当应用程序处于后台状态时,我必须启动两个不同的实验,
- 当通知到达用户但尚未点击时。(这没有实现)
- 在所有通知中,用户点击通知警报并打开应用程序的次数。(这是实现的)
我使用了以下方法:当用户通过点击警报消息来响应通知时,系统会调用以下方法并返回结果。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
如果您的应用程序在前台并且有通知到达,通知中心会调用以下方法将通知直接发送到您的应用程序。
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)