本文介绍了如果当用户点击通知时应用程序已经在后台运行,你如何获得推送通知的有效负载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果向用户显示推送通知并且用户点击它并且应用程序从后台状态进入前台,那么应用程序如何获取通知的负载?>

因为应用程序已经在运行 didFinishLaunchingWithOptions:不会被调用,因为当推送到达时应用程序在后台 didReceiveRemoteNotification:不会被调用.

解决方案

因为当推送到达时应用程序在后台 didReceiveRemoteNotification: won't have been called."

如果应用程序在后台并在用户点击通知时切换到前台,则应调用此或 didReceiveRemoteNotification:withExpirationHandler.

但是我遇到了这样的情况,因为推送的内容不正确,因此无法正常工作,我不记得详细信息,但请仔细检查那里的内容.

If a push notification is displayed to the user and the user taps it and the app is brought to the foreground from a background state then how can the app get the payload of the notification?

Because the app is already running didFinishLaunchingWithOptions: won't get called and because the app was in the background when the push arrived didReceiveRemoteNotification: won't have been called.

解决方案

"because the app was in the background when the push arrived didReceiveRemoteNotification: won't have been called."

This, or didReceiveRemoteNotification:withExpirationHandler, should get called if the app is in the background and gets switched to the foreground when the user taps on the notification.

However I got into a situation when this wasn't working as the reason was the content of the push was incorrect, I can't remember the details but double check what's in there.

这篇关于如果当用户点击通知时应用程序已经在后台运行,你如何获得推送通知的有效负载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:21