I am trying to display a simple notification after a set amount of time which will later open the app and show a form to give feedback but am having a number of problems.
With the current code below I receive warnings in ADB as follows:
06-27 12:56:21.387 19257 19277 I Corona : WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘badge’
06-27 12:56:21.387 19257 19277 I Corona : WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘alert’
06-27 12:56:21.387 19257 19277 I Corona : WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘custom’
The notification then does not appear after the set time. When I then close the app (by swiping it away in the app list) and open it again, the notification appears instantly as the app starts. On top of this, when I tap the notification the app does not open. If I schedule multiple notifications they all appear when restarting the app and if they are stacked in the android notification bar the app does open when the stack is tapped.
main.lua (simplified):
notifications = require( "plugin.notifications.v2" ) composer = require( "composer" ) local launchArgs = ... -- Listen for notifications function onNotification( event ) print( event.name ) if ( event.custom ) then print( event.custom.foo ) end if ( event.type == "local" ) then -- Handle the local notification local badgeNum = native.getProperty( "applicationIconBadgeNumber" ) if ( badgeNum \> 0 ) then badgeNum = badgeNum - 1 native.setProperty( "applicationIconBadgeNumber", badgeNum ) end elseif ( event.type == "remote" ) then -- Handle the push notification if ( event.badge and event.badge \> 0 ) then native.setProperty( "applicationIconBadgeNumber", event.badge - 1 ) end end end Runtime:addEventListener( "notification", onNotification ) if ( launchArgs and launchArgs.notification ) then onNotification( launchArgs.notification ) end composer.gotoScene("core.loading")
homeTab.lua (simplified):
local composer = require( "composer" ) local scene = composer.newScene() local feedbackNotif function scene:create( event ) local sceneGroup = self.view if(feedbackNotif) then notifications.cancelNotification(feedbackNotif) end local options = { alert = "Were you at " .. openapp.preferences.geo.name .. "? Leave your feedback!", badge = 0, custom = { target = "feedback" } } local utcTime = os.date( "!\*t", os.time() + 20 ) feedbackNotif = notifications.scheduleNotification( utcTime, options ) --feedbackNotif = notifications.scheduleNotification( 20, options ) --using this line stops warnings from appearing Runtime:addEventListener( "notification", onNotification ) end
Tried changing to the legacy plugin but that behaved exactly the same way so switched back as I hope to use firebase later in the project for push notifications.
I can’t work out what is causing all these issues, any help would be greatly appreciated!