我有4个场景iOS版 - 阅读,一旦收到推送通知
当应用程序没有启动
给出的应用程序不启动或杀死
当推送通知接收
并开通该应用程序不需要点击通知
然后应用程序应该捕获通知。
当应用程序在前台
鉴于前景
运行时,推送通知接收
然后应用程序应该捕获通知的应用程序运行。
当应用程序在后台
由于应用程序在后台
运行时,推送通知接收
,打开应用程序,而不攻通知
然后应用程序应该捕获通知运行。
当应用程序未启动,清除通知
给出的应用程序没有启动或杀死
当推送通知接收
而用户清除通知
,打开应用程序
然后应用程序应该捕获通知。
第3方案正常工作与下面的代码
的最后一个场景是没有工作当应用程序未启动,清除通知
的AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { requests in
for request in requests {
self.setNotification(userInfo: request.request.content.userInfo as NSDictionary)
}
})
}
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
setNotification(userInfo: userInfo as NSDictionary)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
setNotification(userInfo: userInfo as NSDictionary)
}
**你不能** 想象一下,你有5个通知在屏幕上。你解雇所有5人,然后你启动应用程序。 应用程序应该如何知道应该考虑哪个通知? – Honey
谢谢@Paras Gorasiya – Vignesh
@Honey这是我的问题?有什么方法可以在没有restAPI的情况下获得这些通知。 – Vignesh