Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

What is the correct way to handle a user clicking a push notification to open the app?
Started by henrik5 May 23 2018 06:31 AM

1 reply to this topic
push notifications
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

henrik5

[GLOBAL: userInfoPane.html]
henrik5
  • Contributor

  • 240 posts
  • Corona SDK

I want a method to be triggered by this action and read a custom field from the push JSON. A custom ID to take the user to the story they were interested in. What's the correct way now and are there gotchas like platform differences between Android and IOS?



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 23,955 posts
  • Corona Staff

Push notifications have a pretty well defined set of behaviors on how the app interacts:

 

If you tap on the app icon to start it, or bring it back to the foreground, all push notifications will be lost. If the user chooses to interact with the push notification then you will get one of two behaviors.  If the app is not running (not backgrounded, cold start), the notification will be made available to your app via launchArgs. If your app is backgrounded, it will be brought to the foreground and you will get a notification event.  

 

There is a third behavior, if the app is actively in the foreground when the notification arrives, you will get a notification event without the user having to interact with the push notification.

 

Both the launchArgs and the notification event contain the same table of information. One of the items in that table is a sub-table of custom data (event.custom). It's up to your push sending platform to populate this table. I believe it must be named "custom".  See:

 

https://docs.coronalabs.com/guide/events/appNotification/index.html

 

This doc is really for local notifications, but there is an example of the custom table included:

 

https://docs.coronalabs.com/plugin/notifications/scheduleNotification.html

 

Rob




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: push, notifications