swift - Swift 中获取通知到来的时间

标签 swift push-notification

当我的设备收到通知时,我可以获取本地时间吗?我的意思是,如果我在后台模式下收到通知,当我点击它时,我想知道设备收到通知的时间,例如 10 秒之前。或者它仅在服务器推送时从有效负载进行配置?

最佳答案

如果您使用的是本地通知,您可以自行保存, 对于远程通知,告诉服务器人员向您发送通知时间, 然后当收到通知时,您可以保存详细信息

我正在分享下面的代码,如何在收到通知时获取响应,我正在使用此代码推送到其他 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()
}

关于swift - Swift 中获取通知到来的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54861156/

相关文章:

php - 推送通知

swift - 在整数前包含零

arrays - 比较协议(protocol)引用

iphone - 应用程序未运行时处理推送通知

ios - 我无法发送推送通知来测试 Flight Expo 独立应用程序

iphone - objective-c 的初学者推送通知教程

iphone - 推送通知消息ios的最大长度

swift - 关于 Swift Playground 中的 UIImage

swift - Realm 写入阻塞主线程

swift - 从 url 异步加载 anchor 不起作用