应用程序被杀死时的 iOS 推送通知 [英] iOS Push Notification When app is killed

查看:67
本文介绍了应用程序被杀死时的 iOS 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was wondering how does WhatsApp handle the Video Push Notification when the app is killed from the background. Taking into consideration that the app icon is clicked and not the notification.

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

1- The Push Notification keeps showing every 5 seconds

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

2- The Ringtone plays single time although the app keeps showing push notifications for around 30 seconds.

推荐答案

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

When app is in killed state, didReceiveRemoteNotification method will not be called. Then on the tap of notification application(_:didFinishLaunchingWithOptions) method will be called. launchOption contains the payload if app is launched by tap on notification. For that write the given code in this method:

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

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

All your payload data will be available in launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] & perform your app logic(navigation..) from there.

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

Refer this link for effective push notifications handling

这篇关于应用程序被杀死时的 iOS 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆