On receiving notification change the scene

I’m new to Corona so sorry if I’m missing something obvious.  I have GameThrive set up and I’m receiving notifications properly on both Android and iOS; it was super easy to setup so kudos there.

For whatever reason I am unable to trigger a scene change on notification press.  In this particular example I am sending Additional Data of {“COC”:""}  to popup the notification (which is working to that point) and on pressing “learn more” I would like to transition the user to the COC scene, I just can’t seem to get that to happen.

I fear I am misunderstanding something scope related so any help is appreciated.

As a secondary question id also be interested in jumping a user to a specific scene without the notification if that is possible as well.

-- include Corona's "widget" library local widget = require "widget" local composer = require "composer" -- This function gets called when the player opens a notification or one is received when the app is open and active. function DidReceiveRemoteNotification(message, additionalData, isActive) print("DidReceiveRemoteNotification:Messsage: " .. message) if (additionalData) then if (additionalData.COC) then native.showAlert( "Challenge Of Champions", message, { "Dismiss","Learn More" },onNotificationComplete ) elseif(additionalData.actionSelected) then -- Interactive notification button pressed native.showAlert("Button Pressed!", "ButtonID:" .. additionalData.actionSelected, { "OK"} ) end end end local GameThrive = require("plugin.GameThrivePushNotifications") GameThrive.Init("XXXXXX", "XXXXXXX", DidReceiveRemoteNotification) -- show current scale factor in terminal local deviceWidth = ( display.contentWidth - (display.screenOriginX \* 2) ) / display.contentScaleX local scaleFactor = math.floor( deviceWidth / display.contentWidth ) print("scale : " .. scaleFactor .."x") -- show default status bar (iOS) display.setStatusBar( display.DefaultStatusBar ) -- set up screen options on scene fade local options = { effect = "fade", time = 100, params = {} } -- event listeners for tab buttons: local function onHome( event ) composer.gotoScene( "HomeScreen",options ) end local function onSchedule( event ) composer.gotoScene( "Schedule",options ) end local function onActivities( event ) composer.gotoScene( "Activities",options ) end local function onVote1( event ) composer.gotoScene( "Vote1",options ) end local function onCOC( event ) composer.gotoScene( "COC",options ) end local function onNotificationComplete( event ) if event.action == "clicked" then local i = event.index if i == 1 then -- Do nothing - user selected OK ; dialog will simply dismiss elseif i == 2 then -- User selected Learn more go to Something composer.gotoScene( "COC",options ) end end end -- create a tabBar widget with two buttons at the bottom of the screen -- table to setup buttons local tabButtons = { { label="Home", defaultFile="icon1.png", overFile="icon1-down.png", width = 32, height = 32, onPress=onHome, selected=true }, { label="Schedule", defaultFile="icon2.png", overFile="icon2-down.png", width = 32, height = 32, onPress=onSchedule }, { label="Activities", defaultFile="icon1.png", overFile="icon1-down.png", width = 32, height = 32, onPress=onActivities }, { label="COC", defaultFile="icon2.png", overFile="icon2-down.png", width = 32, height = 32, onPress=onCOC }, } -- create the actual tabBar widget local tabBar = widget.newTabBar{ top = display.contentHeight - 50, -- 50 is default height for tabBar widget buttons = tabButtons } onHome() -- invoke first tab button's onPress event manually

It sounds like your getting to line 11 if your seeing your “Challenge Of Champions” popup.  Can you add a print above the following lines to make sure it is getting into the onNotificationComplete callback; 60, 61, and 65?

If your seeing all 3 prints in your device’s log can you try running line 11 after line 86 to make sure your popup flow works outside of the receiving a push notification flow?

For your 2nd question; DidReceiveRemoteNotification will be called if the user is currently using your app when a push notification comes in. It also will not be displayed to the notification area on the device. You can use isActive to determine if the user opened your app from a notification or true if they got the notification when they are actively using your app.

Thanks.

Thanks Jkasten, I was able to find my issue and I appreciate you clarifying my 2nd question as well.

Glad to hear you got it working. Could you let us know what you had to change to get it working? It will help others who may find this thread in the future.

Thanks.

I moved the onNotificationComplete function to line 5  above the DidReceiveRemoteNotification and it is firing correctly now.

added in the isActive catch

function DidReceiveRemoteNotification(message, additionalData, isActive) if (additionalData) then if (additionalData.COC) then if (isActive) then native.showAlert( "Challenge Of Champions", message, { "Dismiss","Learn More" },onNotificationComplete ) else composer.gotoScene( "COC",options ) end elseif(additionalData.actionSelected) then -- Interactive notification button pressed native.showAlert("Button Pressed!", "ButtonID:" .. additionalData.actionSelected, { "OK"} ) end end end 

It sounds like your getting to line 11 if your seeing your “Challenge Of Champions” popup.  Can you add a print above the following lines to make sure it is getting into the onNotificationComplete callback; 60, 61, and 65?

If your seeing all 3 prints in your device’s log can you try running line 11 after line 86 to make sure your popup flow works outside of the receiving a push notification flow?

For your 2nd question; DidReceiveRemoteNotification will be called if the user is currently using your app when a push notification comes in. It also will not be displayed to the notification area on the device. You can use isActive to determine if the user opened your app from a notification or true if they got the notification when they are actively using your app.

Thanks.

Thanks Jkasten, I was able to find my issue and I appreciate you clarifying my 2nd question as well.

Glad to hear you got it working. Could you let us know what you had to change to get it working? It will help others who may find this thread in the future.

Thanks.

I moved the onNotificationComplete function to line 5  above the DidReceiveRemoteNotification and it is firing correctly now.

added in the isActive catch

function DidReceiveRemoteNotification(message, additionalData, isActive) if (additionalData) then if (additionalData.COC) then if (isActive) then native.showAlert( "Challenge Of Champions", message, { "Dismiss","Learn More" },onNotificationComplete ) else composer.gotoScene( "COC",options ) end elseif(additionalData.actionSelected) then -- Interactive notification button pressed native.showAlert("Button Pressed!", "ButtonID:" .. additionalData.actionSelected, { "OK"} ) end end end