Notifications plugin when app not active

Hello everybody,

I am testing the notification plugin with Firebase.

I managed to register the device and receive a notification sent from firebase console when the app is active.

But how to receive a notification when the application is not active?

Can someone help?

Hi @Lourenco,

It will help if you provide more details for others (and staff). Which exact plugin, “plugin.notifications.v2”? Which platform, iOS or Android? What does your “config.lua” file look like? Etc.

Thanks,

Brent

Hi Brent,

I am using “plugin.notifications.v2” and testing on an iPhone device.

Here is my config.lua :

application = { content = { width = 320, height = 480, scale = "letterbox", }, application = { notification = { google = { projectNumber = "594235633861", }, iphone = { types = { "badge", "sound", "alert" }, }, }, }, }

and my main.lua :

local notifications = require( "plugin.notifications.v2" ) local deviceToken = notifications.getDeviceToken() local launchArgs = ... local function onNotification (event) if event.type == "remoteRegistration" then -- device registered deviceToken = notifications.getDeviceToken() native.showAlert("remoteRegistration", deviceToken, { "OK" }) else -- A push notification received native.showAlert("Push received", "message", { "OK" }) end end if ( launchArgs and launchArgs.notification ) then onNotification ( launchArgs.notification ) end notifications.registerForPushNotifications( { useFCM=true } ) -- Set up a notification listener. Runtime:addEventListener("notification", onNotification)

The primary issue I see is that you have a separate “application” table nested in the main “application” table within “config.lua”. That is not the correct structure… there should only be one top-level “application” table which contains the various child tables.

Brent

Thank you Brent , modified the config.lua as follows.

But still, when app is inactive or in background, I get no notification.

application = { content = { width = 320, height = 480, scale = "letterbox", }, notification = { google = { projectNumber = "594235633861", }, iphone = { types = { "badge", "sound", "alert" }, }, }, }

Are you not seeing the notifications show up in the status bar at the top of the device?

Hello Rob,

finally got it working.

Seems that when APNS certificates are not uploaded on Firebase we receive notifications when app is active only.

I uploaded the APNS certificates and now I receive notifications whatever the state of the app.

Thank you for you help.