从主屏幕启动应用程序无法获得远程推送有效负载?但是从通知中心启动工作 [英] Launch app from homescreen can't get remote push payload? But launch from Notification Center works

查看:122
本文介绍了从主屏幕启动应用程序无法获得远程推送有效负载?但是从通知中心启动工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从主屏幕启动应用无法获得远程推送有效负载?但是从通知中心启动工作。



首先,应用未运行。收到远程推送通知后,用户不会立即启动带有通知的应用程序。然后用户点击通知中心的通知启动应用程序,我可以从 launchOptions 获得推送有效负载:

   - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
NSDictionary * userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo){
//做推送有效载荷。
}
}

但是如果用户通过点击应用图标来启动应用主屏幕,我无法从 launchOptions 获得推送有效负载,尽管应用程序:didFinishLaunchingWithOptions:被调用。



再次:


  1. 应用程序未运行。

  2. 用户在收到推送通知时无法启动应用程序。

  3. 稍后,从通知中心启动应用程序并从launchOptions获取推送有效负载。

  4. 启动来自主屏幕的应用程序无法从launchOptions获得推送有效负载。

这是SDK中的错误吗?如何通过从主屏幕启动应用程序获得推送有效负载?



谢谢!

解决方案

您不能。



您只能在从通知中心启动时获得有效负载,因为这意味着用户对该通知感兴趣。



例如,如果我收到Tweetbot的回复并且我想看到它,我会点击通知,但如果我只想检查我的推文,我会正常打开应用程序。 / p>

如果有效负载包含用户必须接收的信息,应用程序应联系您的服务器并检索它。


Launch app from homescreen can't get remote push payload? But launch from Notification Center works.

At first, app is NOT running. After received remote push notification, user doesn't launch app with the notification at once. Then user taps on the notification in Notification Center to launch app, I can get the push payload from launchOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if(userInfo) {
        //do some works with push payload.
    }
}

But if the user launch app by tapping app icon from homescreen, I can't get the push payload from launchOptions, although application:didFinishLaunchingWithOptions: is called.

Again:

  1. App is NOT running.
  2. User doesn't launch app when received push notification.
  3. Later, launch app from Notification Center and get push payload from launchOptions.
  4. Launch app from homescreen can not get push payload from launchOptions.

Is this a bug in SDK? How can I get push payload by launching app from homescreen?

Thanks!

解决方案

You can't.

You only get the payload when launching from Notification Center because it means the user is interested on that notification.

For example, if I get a reply on Tweetbot and I want to see it, I tap on the notification, but if I only want to check my tweets, I open the app normally.

If the payload has information that the user HAS to receive, the app should contact your server and retrieve it.

这篇关于从主屏幕启动应用程序无法获得远程推送有效负载?但是从通知中心启动工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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