Double notification call

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

Have you tried putting 

return true 

 at the end of your function.

Just tried adding return true, but no luck

Did you ever figure this out? I’m upgrading a 2 year old app of mine that used to work fine. Now I’m seeing the behavior you discribed. Most notably when the app is in the background but the device is unlocked. If the device is asleep I just see the one notification.

Hey Jeremy, unfortunately I did and didn’t figure this out. I no longer have the double up problem, but it kind of stopped on it’s own, so I can’t give you any steps to resolve it. Sorry I can’t be more help. I’m assuming you’ve tried the good old ‘update to the latest version’ trick. Beyond that I’m afraid I’m useless.

Can you tell me more about your environment?

Windows or OS X?

What are you using for an Editor?

What version of Corona SDK are you using?

Does it happen when you build and run on a device?

Rob

Thanks Brad for responding.

Rob, I’m developing on a Mac OS X. I’m using Sublime Text as an editor. I’ve tried 2888, 2874 and the last public release 2830. It only happens when I build for a device. I guess I should say I only notice the issue on an actual device. Only when the device is unlocked and the app is in the background do I see the repeat notifications.

I am requiring the notifications plugin outside of main.lua. I’ve separated my local notifications from the remote notification handling into two files. Somewhere in the docs i recall a mention of handling things in main.lua. Could that cause this behavior? I hate complicating main.lua any more than absolutely necessary.

When you say arrive twice, do you mean when you tap on one of the notifications to bring your app into the foreground the app gets two notification events or do you mean your device receives two events that you can interact with?

This isn’t the cause of your issue, but I wouldn’t call regsiterForPushNotifications() until after you’ve set up the notification event handler.

When my app is in the background and the device is awake, the device slides in two notifications. The same 2 about a second apart. I’ve been able to reproduce the issue consistently on 3 iOS devices. I haven’t tried Android.

The push server is only sending one notification. When the app is in the foreground, the device vibrates only once to indicate it received a single notification. When the device is asleep, it only presents a single notification. The issue only presents itself when the app in in the background and the device is awake.

I’m going to see if I can’t put together a simple app to reproduce the issue.

I wrote a tiny remote notifications app to try to reproduce the problem and I could not reproduce it, so the good news is there must be some way I can work around this issue. Whatever I’m doing wrong is causing an iOS bug to manifest itself. The issue is described in this forum post:

https://forums.developer.apple.com/thread/28115

I get the same behavior and corresponding warning in the devices logs that others are reporting:

Jun 17 16:02:43 Jeremys-iPhone SpringBoard[58] <Warning>: SBLockScreenNotificationListController: Attempting to remove a bulletin I don’t have

Jun 17 16:02:46 Jeremys-iPhone SpringBoard[58] <Warning>: Unbalanced calls to begin/end appearance transitions for <SBBannerButtonViewController: 0x164857c70>.

Jun 17 16:02:46 Jeremys-iPhone SpringBoard[58] <Warning>: SBLockScreenNotificationListController: Attempting to remove a bulletin I don’t have

It would seem I’m somehow causing Corona to call [registerUserNotificationSettings:] twice.

Same problem here. Amazing that there was no resolution to this one year later. @jeremy_b did you find a solution?

Edit: Still seeing the issue, nvm the previous I posted didn’t fix it. Did things work out for everyone in this thread?

Hi @jjoku.

What version of Corona are you running?

What device are you testing on?

Can you post your build.settings file?

Can you post your code where you are setting up your push notification handler?

What service are you using to send the push notifications?

Thanks

Rob

Hi Rob! I’m running Corona v2017.3114 and testing on an iPhone 6 iOS 10

Build.settings:

settings = { splashScreen = { enable = false }, plugins = { ["plugin.notifications"] = { publisherId = "com.coronalabs", }, ["plugin.google.iap.v3"] = { publisherId = "com.coronalabs", supportedPlatforms = {android=true} }, ["CoronaProvider.analytics.flurry"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, android=true } }, ["CoronaProvider.gameNetwork.google"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["plugin.amazon.iap"] = { publisherId = "com.coronalabs" }, --[[["plugin.chartboost"] = { -- required publisherId = "com.swipeware", },--]] }, orientation = { default = "portrait", supported = { "portrait" } }, iphone = { plist = { UILaunchImages = { { -- iPhone 4 Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{320, 480}" }, { -- iPhone 5 Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default-568h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{320, 568}" }, { -- iPad Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default-Portrait", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{768, 1024}" }, { -- iPhone 6 Portrait ["UILaunchImageMinimumOSVersion"] = "8.0", ["UILaunchImageName"] = "Default-667h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{375, 667}" }, { -- iPhone 6 Plus Portrait ["UILaunchImageMinimumOSVersion"] = "8.0", ["UILaunchImageName"] = "Default-736h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{414, 736}" }, }, UIAppFonts = { "Arial Rounded Bold.ttf", "HelveticaNeue.ttf", "HelveticaNeue-Bold.ttf", "HelveticaNeue-BoldItalic.ttf", "HelveticaNeue-Light.ttf", "HelveticaNeue-Italic.ttf", "HelveticaNeue-LightItalic.ttf", "HelveticaNeueLTStd-Th.otf", "SourceSansPro-Regular.ttf", "SourceSansPro-Bold.ttf", "SourceSansPro-BoldItalic.ttf", "SourceSansPro-Light.ttf", "SourceSansPro-Italic.ttf", "SourceSansPro-LightItalic.ttf", "SourceSansPro-ExtraLight.ttf", }, CFBundleIconFile = "Icon.png", CFBundleIconFiles = { --[["Icon.png", "Icon@2x.png", "Icon-40.png", "Icon-40@2x.png", "Icon-40@3x.png", "Icon-60.png",--]] "Icon-60@2x.png", --[["Icon-60@3x.png", "Icon-72.png", "Icon-72@2x.png",--]] "Icon-76.png", "Icon-76@2x.png", --[["Icon-Small-50.png", "Icon-Small-50@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small@3x.png"--]] }, UIPrerenderedIcon = true, UIStatusBarHidden = true, UIBackgroundModes = { "remote-notification" }, }, }, android = { usesPermissions = { "android.permission.WRITE\_EXTERNAL\_STORAGE", "android.permission.INTERNET", "com.android.vending.BILLING", "android.permission.RECEIVE\_BOOT\_COMPLETED", "android.permission.ACCESS\_NETWORK\_STATE", "com.google.android.c2dm.permission.RECEIVE", ".permission.C2D\_MESSAGE", }, }, }

Handler code:

local notifications = require("plugin.notifications") local function onNotification(event) local typ = event.type native.setProperty("applicationIconBadgeNumber", 0) if(typ == "remoteRegistration") then print(event.token) elseif(typ == "remote") then end end Runtime:addEventListener("notification", onNotification) notifications.registerForPushNotifications() if launchArgs and launchArgs.notification and launchArgs.notification.custom then local notification = launchArgs.notification if notification.custom['url'] then system.openURL(notification.custom['url']) end end

I’m using OneSignal, but this issue occurs before I send a notification. It occurs on the registration as it prompts the user if they want to allow push notification twice and among other things and is causing a lot of issues

Hi again, sorry Rob. As I was pasting my code I took another hard look at it as I was editing and I was reminded that you guys had moved to a v2 version of the notification plugin. I updated my code and vóila, problem is no more.

Thanks again for asking me to paste the code at any rate, works beautifully now it seems! :slight_smile: Also for anyone else seeing this in the future, v2 fixed it for me