应用程序被杀死时的 iOS 推送通知

Ali*_*ahr 5 apple-push-notifications ios whatsapp

我想知道当应用程序从后台被杀死时,WhatsApp 如何处理视频推送通知。考虑到点击的是应用程序图标而不是通知。

1- 推送通知每 5 秒显示一次

2- 尽管应用程序会持续显示推送通知约 30 秒,但铃声只播放一次。

小智 5

当应用程序处于终止状态时,不会调用 didReceiveRemoteNotification 方法。然后点击通知应用程序(_:didFinishLaunchingWithOptions) 方法将被调用。如果通过点击通知启动应用程序,launchOption 包含有效负载。为此,在此方法中编写给定的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
       if launchOptions != nil{
         let userInfo = launchOptions? 
         [UIApplicationLaunchOptionsKey.remoteNotification]
          if userInfo != nil {
        // Perform action here
         }
    }
Run Code Online (Sandbox Code Playgroud)

您的所有负载数据都将在 launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] 中可用,并从那里执行您的应用程序逻辑(导航..)。

请参阅此链接以获取有效的推送通知处理