我可以在设备收到通知时获得本地时间,我的意思是,如果我在背景模式上收到通知,并且当我单击它时,我想知道设备收到的时间,示例10s。或仅在服务器按下有效载荷的配置?
如果您使用的是本地通知,则可以自己保存,对于远程通知,请告诉服务器人员向您发送带有通知的时间然后,当收到通知时,您可以保存详细信息
我正在分享以下代码如何在收到通知时如何获取响应,我正在使用此代码推送到其他VC
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let notificationTitle = response.notification.request.content.title
let info = response.notification.request.content.userInfo
let data = info["moduledata"] as? String ?? ""
switch notificationTitle {
case "Notice Added":
let vc = NoticeDetailViewController()
vc.noticeID = data
let navVC = UINavigationController(rootViewController: vc)
window?.rootViewController = navVC
case "Practicework Added":
let vc = HomeworkDetailViewController()
vc.id = data
let navVc = UINavigationController(rootViewController: vc)
window?.rootViewController = navVc
default:
print("")
}
completionHandler()
}