Notice event inside the app not fired.

So … followed all the directions and have notifications working at least up until inside of the app.

The iOS device receives the notice and adds a Badge to the app.  However, when i launch the app i do not receive the event telling me of the new notification.

Inside of the app I have the following at the Very Top of main.lua

local function DidReceiveRemoteNotification(message, additionalData, isActive)     print("ONE SIGNAL NOTIFICATION RECEIVED!")     if (additionalData) then         if (additionalData.discount) then             native.showAlert( "Discount!", message, { "OK" } )             -- Take user to your app store         elseif (additionalData.actionSelected) then -- Interactive notification button pressed             native.showAlert("Button Pressed!", "ButtonID:" .. additionalData.actionSelected, { "OK"} )         end     else         native.showAlert("OneSignal Message", message, { "OK" } )     end end local OneSignal = require("plugin.OneSignal") OneSignal.Init("my one signal id for the app in question", "my google project id", DidReceiveRemoteNotification)

The DidReceiveRemoteNotification is not firing when i open the app or if i receive a notice if the app is already open.

Any thoughts?

Appreciated!

m

Bit more info.  I can from inside the app tag a user and that info shows up on the OneSignal site … so i would assume that the init is working.

Just never seeing the DidReceiveRemoteNotification getting triggered

Ok well think i am getting this figured out.  Not sure exactly why it was not working quite right before.  However, it seems that if you have a notification and the app is not running and you tap the app icon rather than the notification then the event does not fire.  Originally, i was thinking you would get to process incoming notifications even if you did not tap on the notification.

So bit confusing …

  1. if app is running: notification callback is fired

  2. if app is not running and you tap on the notification at the iOS level … the app starts and the callback is fired

  3. if app is not running and there is a pending notification but you start the app via the app icon then the Callback is NOT fired.

Not sure that makes sense to me … if i am trying to pass info to the app via these messages then i will not receive a chance to deal with the message in case #3.

???

Hello,

This is correct, the DidReceiveRemoteNotification callback only fires when a notification is received when the user is in your app or when that notification is opened when tapping on the notification itself. Case 1 and 2 in your example. Since iOS itself does not provide a way to get unopened notifications there isn’t a way our OneSignal plugin can detect this. 

However if you need to get the contents of these unopened notifications when you open your app their are 2 options to work around this iOS limitation.

  1. When you send a notification from OneSignal store the same values on your server for the user. Then when your app is opened read the notification content from your server.

  2. Send all notifications with content_available enabled which wakes up your app in the background. You will then need to add Objective-C code to implement the application:didReceiveRemoteNotification:fetchCompletionHandler: selector to handle receiving this contents. You will need to save this notification on the device so you can retrieve it later when the user opens the app. The caveats are that this will only work for Enterprise builds of your app from Xcode, the user must not force kill your app or turn off background data, and must be on iOS 7 or newer(about 98% of iOS users).

Thanks.

Thanks for the assistance.

I have not gotten to the Android version yet.

If you do not mind … Are there any issues that i should know about for Android?

This would be excellent info to add to the OneSignal or Corona docs 

Cheers,

m

The affects are the same with Android are basically the same where your cases 1 and 2 will work but case 3 does not fire the callback. The first work around also applies. The 2nd work around will require the same logic as on Android with Android. Here are the details on implement this on Android though:

Send all notifications with Background Data enabled, this wakes up a BroadcastReceiver defined in your AndroidManifest.xml file. You will need to implement this class in Java and handle receiving the contents. Then save it on the device so you can retrieve it later when the user opens the app. The only caveats is that this will only works for Enterprise builds of your app. If the user saw your notification the BroadcastReceiver will get called.

Thanks.

Bit more info.  I can from inside the app tag a user and that info shows up on the OneSignal site … so i would assume that the init is working.

Just never seeing the DidReceiveRemoteNotification getting triggered

Ok well think i am getting this figured out.  Not sure exactly why it was not working quite right before.  However, it seems that if you have a notification and the app is not running and you tap the app icon rather than the notification then the event does not fire.  Originally, i was thinking you would get to process incoming notifications even if you did not tap on the notification.

So bit confusing …

  1. if app is running: notification callback is fired

  2. if app is not running and you tap on the notification at the iOS level … the app starts and the callback is fired

  3. if app is not running and there is a pending notification but you start the app via the app icon then the Callback is NOT fired.

Not sure that makes sense to me … if i am trying to pass info to the app via these messages then i will not receive a chance to deal with the message in case #3.

???

Hello,

This is correct, the DidReceiveRemoteNotification callback only fires when a notification is received when the user is in your app or when that notification is opened when tapping on the notification itself. Case 1 and 2 in your example. Since iOS itself does not provide a way to get unopened notifications there isn’t a way our OneSignal plugin can detect this. 

However if you need to get the contents of these unopened notifications when you open your app their are 2 options to work around this iOS limitation.

  1. When you send a notification from OneSignal store the same values on your server for the user. Then when your app is opened read the notification content from your server.

  2. Send all notifications with content_available enabled which wakes up your app in the background. You will then need to add Objective-C code to implement the application:didReceiveRemoteNotification:fetchCompletionHandler: selector to handle receiving this contents. You will need to save this notification on the device so you can retrieve it later when the user opens the app. The caveats are that this will only work for Enterprise builds of your app from Xcode, the user must not force kill your app or turn off background data, and must be on iOS 7 or newer(about 98% of iOS users).

Thanks.

Thanks for the assistance.

I have not gotten to the Android version yet.

If you do not mind … Are there any issues that i should know about for Android?

This would be excellent info to add to the OneSignal or Corona docs 

Cheers,

m

The affects are the same with Android are basically the same where your cases 1 and 2 will work but case 3 does not fire the callback. The first work around also applies. The 2nd work around will require the same logic as on Android with Android. Here are the details on implement this on Android though:

Send all notifications with Background Data enabled, this wakes up a BroadcastReceiver defined in your AndroidManifest.xml file. You will need to implement this class in Java and handle receiving the contents. Then save it on the device so you can retrieve it later when the user opens the app. The only caveats is that this will only works for Enterprise builds of your app. If the user saw your notification the BroadcastReceiver will get called.

Thanks.

Not having success with DidReceiveRemoteNotification firing with app open. Receiving notifications if app is closed. Can you assist?

main.lua

local messagecontent = “”

– This function gets called when the user opens a notification or one is received when the app is open and active.

– Change the code below to fit your app’s needs.

function DidReceiveRemoteNotification(message, additionalData, isActive)

    messagecontent = message

    print("Message= ",message)

    local messagedisplay = display.newText (messagecontent, centerX, centerY, native.systemFont, 22)

    if (additionalData) then

        if (additionalData.discount) then

            print (“1”)

            native.showAlert( “Discount!”, message, { “OK” } )

            – Take user to your app store

        elseif (additionalData.actionSelected) then – Interactive notification button pressed

            print(“2”)

            native.showAlert(“Button Pressed!”, “ButtonID:” … additionalData.actionSelected, { “OK”} )

        end

    else

        print (“3”)

        native.showAlert(“OneSignal Message”, message, { “OK” } )

    end

end

local OneSignal = require(“plugin.OneSignal”)

– Uncomment SetLogLevel to debug issues.

 OneSignal.SetLogLevel(4, 4)

OneSignal.EnableInAppAlertNotification(true)

OneSignal.Init(“xxxxxx”, “############”, DidReceiveRemoteNotification)

local widget = require( “widget” )

display.setStatusBar( display.HiddenStatusBar )                      – hide status bar

–io.output():setvbuf(‘no’)                                 – **debug: disable output buffering for Xcode Console

print();print("<-========================= Program Start =========================->");print()

local titleMsg = display.newText( “Breaking News”, centerX, 23, native.systemFontBold, 18 )

local CoronaBuild = system.getInfo( “build” )

print("Corona Build: "…CoronaBuild)

Also downloaded the example app on git with same result. notification does not fire when tapping the notification and the app opens.

I just tried to build our example and didn’t see any issue with the callback not working.

Can you try ‘native.showAlert’ instead of ‘display.newText’ to makes sure your location setting isn’t an issue of it displaying offscreen. Also what entires are you seeing in the Xcode log or adb logcat?

Can you let us know what build number of Corona you’re using and what OS version you’re testing on?

Thanks.

Not having success with DidReceiveRemoteNotification firing with app open. Receiving notifications if app is closed. Can you assist?

main.lua

local messagecontent = “”

– This function gets called when the user opens a notification or one is received when the app is open and active.

– Change the code below to fit your app’s needs.

function DidReceiveRemoteNotification(message, additionalData, isActive)

    messagecontent = message

    print("Message= ",message)

    local messagedisplay = display.newText (messagecontent, centerX, centerY, native.systemFont, 22)

    if (additionalData) then

        if (additionalData.discount) then

            print (“1”)

            native.showAlert( “Discount!”, message, { “OK” } )

            – Take user to your app store

        elseif (additionalData.actionSelected) then – Interactive notification button pressed

            print(“2”)

            native.showAlert(“Button Pressed!”, “ButtonID:” … additionalData.actionSelected, { “OK”} )

        end

    else

        print (“3”)

        native.showAlert(“OneSignal Message”, message, { “OK” } )

    end

end

local OneSignal = require(“plugin.OneSignal”)

– Uncomment SetLogLevel to debug issues.

 OneSignal.SetLogLevel(4, 4)

OneSignal.EnableInAppAlertNotification(true)

OneSignal.Init(“xxxxxx”, “############”, DidReceiveRemoteNotification)

local widget = require( “widget” )

display.setStatusBar( display.HiddenStatusBar )                      – hide status bar

–io.output():setvbuf(‘no’)                                 – **debug: disable output buffering for Xcode Console

print();print("<-========================= Program Start =========================->");print()

local titleMsg = display.newText( “Breaking News”, centerX, 23, native.systemFontBold, 18 )

local CoronaBuild = system.getInfo( “build” )

print("Corona Build: "…CoronaBuild)

Also downloaded the example app on git with same result. notification does not fire when tapping the notification and the app opens.

I just tried to build our example and didn’t see any issue with the callback not working.

Can you try ‘native.showAlert’ instead of ‘display.newText’ to makes sure your location setting isn’t an issue of it displaying offscreen. Also what entires are you seeing in the Xcode log or adb logcat?

Can you let us know what build number of Corona you’re using and what OS version you’re testing on?

Thanks.