简体   繁体   English

Air iOS / Android推送通知记住应用程序启动的时间

[英]Air iOS/Android push notification remember when app launches

I have an app built for iOS and Android which has push notifications. 我有一个为iOS和Android构建的具有推送通知的应用程序。 Everything is working great however I was wondering if there is a way to store the data of the push notification in the app so that when users launch the app after receiving a notification I can show them the message again? 一切都很好,但是我想知道是否有一种方法可以在应用程序中存储推送通知的数据,以便当用户在收到通知后启动应用程序时,我可以再次向他们显示消息吗?

Basically I allow users to share information and/or chat amongst their friends. 基本上,我允许用户在他们的朋友之间共享信息和/或聊天。 If they receive a notification when the app is in the background it comes through as a normal push message but when they launch the app I would like to direct them to the chat feature to see the message again. 如果他们在应用程序处于后台时收到通知,则作为正常的推送消息通过,但是当他们启动应用程序时,我希望将他们定向到聊天功能以再次查看该消息。

I am storing the messages sent in a remote DB but seeing as they have already received the payload it doesn't make much sense for the app to call the remote DB to retrieve the same message. 我将发送的消息存储在远程数据库中,但是看到它们已经收到了有效负载,因此应用程序调用远程数据库来检索相同的消息并没有多大意义。

I am using Distriqt's extensions in AS3 and Air 3.5. 我在AS3和Air 3.5中使用Distriqt的扩展。

Cheers 干杯

I asked Distriqt's support for the same thing a few weeks ago and they explained that there is no way to get the information of the push notification message while the app is closed so they suggested this : - when the user opens the app, you call your server to check if they haven't missed anything, and get the data from there. 几周前,我问过Distriqt对同一事物的支持,他们解释说,在应用程序关闭时无法获取推送通知消息的信息,因此他们建议:-当用户打开应用程序时,您致电服务器检查他们是否没有遗漏任何东西,并从那里获取数据。 If there has been a push, you display the push message as if it was received with the app in the foreground. 如果有推送,则显示推送消息,就像前台收到应用程序时一样。

It's a bit tricky and not very satisfying but it works.. As long as the user follows the path. 这有点棘手,但不是很令人满意,但是可以。.只要用户遵循该路径。 If your user receives the push and chooses not to open your app, he will still get the push message in your app next time he opens it. 如果您的用户收到推送消息并选择不打开您的应用程序,则下次打开该消息时,他仍会在您的应用程序中收到推送消息。

I was having trouble figuring this out too but I found a solution! 我也很难弄清楚这一点,但我找到了解决方案! Basically if a user launches an app (not running in the background) by way of a notification it comes through in the Invoke event, not the usual Notification event. 基本上,如果用户通过通知启动应用程序(不在后台运行),则该应用程序是在Invoke事件(而不是通常的Notification事件)中通过的。 So do this: 这样做:

NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);

private function invoked(evt:InvokeEvent):void
{
    if (evt.reason == InvokeEventReason.NOTIFICATION)
    {
        var payload:Object = Object(evt.arguments[0]);
        // do stuff
    }
}

That's pretty much it. 就是这样。 There's more detail in this blog post here: http://blogs.adobe.com/airodynamics/2012/05/29/push-notifications-support-in-ios/ 在此博客文章中,有更多详细信息: http : //blogs.adobe.com/airodynamics/2012/05/29/push-notifications-support-in-ios/

NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);

doesn't work correctly for Android push notification. 对于Android推送通知无法正常工作。 Android starts with InvokeEventReason.standard all the time, so we cant receive message. Android始终以InvokeEventReason.standard开头,因此我们无法接收消息。 It works only for iOS. 它仅适用于iOS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM