addEventListener "notification" doesn't work on iOS

Hello,

We encountered a problem with iOS notifications.

We are trying to register the user devices but we are no longer receiving the data from the remoteRegistration (we are registering devices with APNS).

This problem was encountered with the legacy, so we tried to switch to the notifications.v2 plugin. But we encounter the same problem after the migration.

It worked before.

On iOS (It works perfectly on Android), the Runtime: addEventListener (“notification”, notificationListener) does not seem to work.

We have no print displayed in the called notificationListener function.

So it never does the remoteRegistration event.

Oddly, it works if we do a live build, but not with a normal build.

Has anyone encountered this problem? 

In advance thank you to the person who will take the time to read my post and will bring me a beginning of solution.

PS: sorry for my bad english.

Here is parts from the code of my main.lua , config.lua and build.settings

Have a nice day!

mail.lua

local notifications = require( "plugin.notifications.v2" ) notifications.registerForPushNotifications() local function notificationListener( event ) print("test of notificationListener") local easyurl = "" if ( event.type == "remoteRegistration" )then print("test of the remoteRegistration") if ( device.isAndroid ) then googleRegistrationId = event.token local message = "This app has successfully registered for Google push notifications." print(message) easyurl = myData.httpsyst..myData.domainesyst..myData.urlpush.."php/apns\_google.php?task=register" else local message = "This app has successfully registered for Ios push notifications." print(message) easyurl = myData.httpsyst..myData.domainesyst..myData.urlpush.."php/apns.php?task=register" end if ( device.isAndroid ) then easyurl=easyurl.."&deviceuid="..urlencode(googleRegistrationId ) else easyurl=easyurl.."&deviceuid="..urlencode(system.getInfo("deviceID")) end if (event.token ~= nil) then easyurl=easyurl.."&devicetoken="..event.token end local headers = {} headers["Content-Type"] = "application/json" local params = {} params.headers = headers network.request ( easyurl, "GET", networkListener, params ) elseif ( event.type == "remote" ) then end end Runtime:addEventListener( "notification", notificationListener )

Config.lua

notification = { iphone = { types = { "badge", "sound", "alert" } }, }

Build.settings

plugins = { ["plugin.notifications.v2"] = { publisherId = "com.coronalabs", }, },

Try moving your register for push notifications call after you setup the listener for it.

Rob

thanks rob, everything seems to work now after some reorganization of the code.

The problem was actually Firebase Analytics.

So, if it can help other people, I would just mention that there is a conflict between the plugin notification.v2 and Scott H Tech Firebase Analytics plugin.

Once Firebase analytics is activated with .init(), the remote registration no longer works. It is therefore necessary to initialize Firebase analytics after the remote registration has taken place.

The problem is mentioned on this other topic:
https://forums.coronalabs.com/topic/68494-firebase-analytics-and-remote-registration/

Have a nice day, and as always, thanks a lot for your kind assistance!

@GBF Thanks for posting your findings, but future readers should also know that  Rob’s input is also correct and applicable.

You should make sure the listener is registered before calling init().

This is true for any listener.  Register, then initiate events.

yes, sorry, I forgot to mention that I had applied the good advice of rob before I realize this other problem of conflict with firebase analytics.

Indeed, the good advice given by rob was part of the code rearrangement that I evoked in my previous post and that made it possible to run my push notifications again.

Thanks a lot. Very good support on corona forums!

Try moving your register for push notifications call after you setup the listener for it.

Rob

thanks rob, everything seems to work now after some reorganization of the code.

The problem was actually Firebase Analytics.

So, if it can help other people, I would just mention that there is a conflict between the plugin notification.v2 and Scott H Tech Firebase Analytics plugin.

Once Firebase analytics is activated with .init(), the remote registration no longer works. It is therefore necessary to initialize Firebase analytics after the remote registration has taken place.

The problem is mentioned on this other topic:
https://forums.coronalabs.com/topic/68494-firebase-analytics-and-remote-registration/

Have a nice day, and as always, thanks a lot for your kind assistance!

@GBF Thanks for posting your findings, but future readers should also know that  Rob’s input is also correct and applicable.

You should make sure the listener is registered before calling init().

This is true for any listener.  Register, then initiate events.

yes, sorry, I forgot to mention that I had applied the good advice of rob before I realize this other problem of conflict with firebase analytics.

Indeed, the good advice given by rob was part of the code rearrangement that I evoked in my previous post and that made it possible to run my push notifications again.

Thanks a lot. Very good support on corona forums!