ios - 如何在 appdelegate 中获取传递的通知详细信息
问题描述
我已经设法通过点击通知打开应用程序时获取通知详细信息,但是如果用户通过单击应用程序图标打开应用程序,是否有任何方法可以在应用程序内获取传递的通知详细信息
func applicationWillResignActive(_ application: UIApplication) {
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.getDeliveredNotifications { (notification) in
print(notification.count)
}
} else {
// Fallback on earlier versions
}
}
在这里我得到了通知计数,但我不知道如何从这里获取通知的详细信息(用户信息)
解决方案
如果您的应用程序被强制关闭(向上滑动)并且用户单击通知打开应用程序,您仍然可以在AppDelegate didFinishLaunchingWithOptions
方法中获取此信息:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if let userInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [String: AnyObject]{
//Here you can use the notification payload information.
}
return true
}
推荐阅读
- html - CSS 网格体育场形状
- javascript - 如何检查数组中的所有对象是否包含相同的键和值?
- parallel-processing - MPI:将解析数据收集到所有进程
- rabbitmq - rabbitmq 与 Splunk 的集成
- python - 杀死敌人后如何添加血液粒子效果?
- python - 如何从文本文件中删除行?
- c# - .NET Core 3.1 中的“通过”控制器操作(获取和返回 JSON)
- vue.js - 为什么我的浏览器不能在 Vue 中使用 WebSockets 进行控制台日志记录?
- r - 新列表中的因子水平 (R)
- mule - 批量插入连接器获取当前索引的索引