I’ve come across a weird issue where everything to do with notifications fires twice. Literally everything. On the simulator I get “WARNING: The ‘plugin.notifications’ library is not available on this platform.” twice.
Both local and push notifications arrive twice.
Here is my main.lua notification code:
local notifications = require( "plugin.notifications" ) notifications.registerForPushNotifications() .... ----------- START PUSH NOTIFICATION SETUP ----------- local function getTimezoneOffset(ts) local utcdate = os.date("!\*t", ts) local localdate = os.date("\*t", ts) localdate.isdst = false -- this is the trick return os.difftime(os.time(localdate), os.time(utcdate)) end local launchArgs = ... if (launchArgs and launchArgs.notification) then if device.isApple and badge ~= 0 then native.setProperty( "applicationIconBadgeNumber", 0 ) end if (launchArgs.notification.custom) then if (launchArgs.notification.custom.msgTitle) then msgTitle = launchArgs.notification.custom.msgTitle end end if (launchArgs.notification.custom.showAlert) then if launchArgs.notification.custom.showAlert == true then native.showAlert( msgTitle, launchArgs.notification.alert, { "OK" } ) end end end local function notificationListener( event ) ------- CLEAR BADGE NUMBER ON APPLE if device.isApple and badge ~= 0 then native.setProperty( "applicationIconBadgeNumber", 0 ) end ------- REGISTER DEVICE WITH PUSHBOTS if ( event.type == "remoteRegistration" ) then local tags = {} local platform if device.isApple then platform = 0 tags.platform = "Apple" else platform = 1 tags.platform = "Google" end local body = json.encode( { token = event.token, platform = platform, tags = tags } ) local headers = { ["X-PUSHBOTS-APPID"] = "xxx", ["X-PUSHBOTS-SECRET"] = "xxx", ["Content-Type"] = "application/json" } local params={} params.body = body params.headers = headers local function networkListener( event ) if ( event.isError ) then print( "Network error: ", event.response ) else print ( "RESPONSE: " .. event.response ) end end local answer = network.request( 'https://api.pushbots.com/deviceToken', "PUT", networkListener, params ) ------- RECEIVE LOCAL NOTIFICATION elseif ( event.type == "local" ) then if (event.custom) then if (event.custom.msgTitle) then msgTitle = event.custom.msgTitle end end --handle the local notification if (event.custom.showMsg) then native.showAlert( msgTitle, event.alert, { "OK" } ) end ------- RECEIVE PUSH NOTIFICATION elseif ( event.type == "remote" ) then if (event.custom) then if (event.custom.msgTitle) then msgTitle = event.custom.msgTitle end end --handle the push notification if (event.custom.showMsg) then native.showAlert( msgTitle, event.alert, { "OK" } ) end end end Runtime:addEventListener( "notification", notificationListener ) local options = { alert = "Wake up!", badge = 2, sound = "astonished.caf", custom = { msgTitle = "Get a job" } } -- TEST LOCAL NOTIFICATION local utcTime = os.date( "!\*t", os.time() + 30 ) local notification = notifications.scheduleNotification( utcTime, options ) ----------- END PUSH NOTIFICATION SETUP -----------
My build.settings and config.lua are all set up properly and everything is working, just twice as well as it should!
Anybody come across this before?
Thanks
Brad
Also for anyone else seeing this in the future, v2 fixed it for me