I can’t get the launch arguments notification data. Help me!
Can you provide more details about what you’re trying to do?
Maybe post some code on how you’re trying to get the notification data?
What type of notifications (GCM, Firebase, Local, iOS, OneSignal?)
What version of Corona are you using?
Rob
I need to get data notification when the user touch on the notification to process the redirect to the corresponding page.
I use the following code to get launch arguments notifications:
local launchArgs = ... local function onNotification( event ) end if ( launchArgs and launchArgs.notification ) then onNotification( launchArgs.notification ) end
I’m using the firebase service (FCM)
And build with the version 2017.3068
LaunchArgs will only be filled on a cold start. If the app is already in memory, but backgrounded, you will get a notification event.
Also 3068 is two public builds old. You will need to update to the latest public build to be able to submit to Google Play since we addressed a security issue that Google is detecting in that build.
Are you cold starting the app or is it already running?
Rob
How to cold start the app?
While the user only closes the application using the back or home key
Please specify more. Thank you!
An app can exist in three states:
-
The app is not running, not in memory. That means if you press the Overview button (rightmost soft key) your app is not in the list of apps. If an app’s icon is tapped on or a notification for the app is interacted with, the app will be started. This is a “cold start”. If you tap on the app’s icon, the app will be started but no information will come in through launchArgs. If you interact with the notification, launchArgs should be populated.
-
The app is running but in the background. If you bring the app to the foreground from the Overview screen, you will not get any notification events. If you interact with the notification, your app will be brought to the foreground and your app will receive a notification event. You won’t get anything in launchArgs.
-
The app is already running in the foreground and a notification comes in you will get a notification event. Again, no info will come into launchArgs.
Rob
Thank Rob!
Hey,
I am having a problem similar to this except my issue is on cold start I still get a normal notification event from the runtime listener but my launchArgs are blank. I have tried switching all sorts of things around but no luck. So whenever I start with a notification I go to a screen based on that, but then afterwards it goes to the login screen because launchArgs is always an empty table. Public build 3184.
local launchArgs = ... local notificationHelper = require( "notificationHelper" ) local composer = require( "composer" ) local notifications = require( "plugin.notifications.v2" ) Runtime:addEventListener( "notification", notificationHelper.onNotification ) if (launchArgs and launchArgs.notification) then notificationHelper.onNotification(launchArgs.notification) else composer.gotoScene( "loginUser", composerOptions ) end
If you’re getting a notification event, the data that would be in launchArgs is in the event table for the notification event. If your app is cold starting, you shouldn’t get a notification event (though this may have changed with FCM messaging on Android). You will get one or the other but not both.
Rob
Hey Rob,
Yea, I am getting the data in the notification, but as you said, I shouldn’t be getting that on cold start, but I am for some reason. I am on iOS 11.2. I have worked around the issue by setting a timer to check for the app to be past the loginUser scene before changing the scene again via the notification data(otherwise I get bumped back to a screen called in loginUser if the user has a token). But it would obviously be nice not to have to do that. Moving the addition of the runtime notification listener to the loginUser scene from main stops the notification from being processed on cold start, but launchArgs is still empty then.
Can you provide more details about what you’re trying to do?
Maybe post some code on how you’re trying to get the notification data?
What type of notifications (GCM, Firebase, Local, iOS, OneSignal?)
What version of Corona are you using?
Rob
I need to get data notification when the user touch on the notification to process the redirect to the corresponding page.
I use the following code to get launch arguments notifications:
local launchArgs = ... local function onNotification( event ) end if ( launchArgs and launchArgs.notification ) then onNotification( launchArgs.notification ) end
I’m using the firebase service (FCM)
And build with the version 2017.3068
LaunchArgs will only be filled on a cold start. If the app is already in memory, but backgrounded, you will get a notification event.
Also 3068 is two public builds old. You will need to update to the latest public build to be able to submit to Google Play since we addressed a security issue that Google is detecting in that build.
Are you cold starting the app or is it already running?
Rob
How to cold start the app?
While the user only closes the application using the back or home key
Please specify more. Thank you!
An app can exist in three states:
-
The app is not running, not in memory. That means if you press the Overview button (rightmost soft key) your app is not in the list of apps. If an app’s icon is tapped on or a notification for the app is interacted with, the app will be started. This is a “cold start”. If you tap on the app’s icon, the app will be started but no information will come in through launchArgs. If you interact with the notification, launchArgs should be populated.
-
The app is running but in the background. If you bring the app to the foreground from the Overview screen, you will not get any notification events. If you interact with the notification, your app will be brought to the foreground and your app will receive a notification event. You won’t get anything in launchArgs.
-
The app is already running in the foreground and a notification comes in you will get a notification event. Again, no info will come into launchArgs.
Rob
Thank Rob!
Hey,
I am having a problem similar to this except my issue is on cold start I still get a normal notification event from the runtime listener but my launchArgs are blank. I have tried switching all sorts of things around but no luck. So whenever I start with a notification I go to a screen based on that, but then afterwards it goes to the login screen because launchArgs is always an empty table. Public build 3184.
local launchArgs = ... local notificationHelper = require( "notificationHelper" ) local composer = require( "composer" ) local notifications = require( "plugin.notifications.v2" ) Runtime:addEventListener( "notification", notificationHelper.onNotification ) if (launchArgs and launchArgs.notification) then notificationHelper.onNotification(launchArgs.notification) else composer.gotoScene( "loginUser", composerOptions ) end
If you’re getting a notification event, the data that would be in launchArgs is in the event table for the notification event. If your app is cold starting, you shouldn’t get a notification event (though this may have changed with FCM messaging on Android). You will get one or the other but not both.
Rob
Hey Rob,
Yea, I am getting the data in the notification, but as you said, I shouldn’t be getting that on cold start, but I am for some reason. I am on iOS 11.2. I have worked around the issue by setting a timer to check for the app to be past the loginUser scene before changing the scene again via the notification data(otherwise I get bumped back to a screen called in loginUser if the user has a token). But it would obviously be nice not to have to do that. Moving the addition of the runtime notification listener to the loginUser scene from main stops the notification from being processed on cold start, but launchArgs is still empty then.