I’m getting an error when receiving a push notification when the app is running:
Success: 200
{“message”: “unknown error”}
message: unknown error
Details:
I am building an app that sends a push notification when ever there is an update to a message stream. Using Coronium, I can successfully send the message through pushbots and it shows as a badge on the app icon and in the notifications window on the device (so far, so good!).
In app is when I get the error (above). Using mod_pushbots (v1.1), the device is registered and the device token is recorded (we know this is working since we can get notifications outside the app).
Server Pushbots call (using Coronium 1.93).
device is retrieved from a database. All of this works when the app is closed.
... local device = answer.result.deviceToken coronium.push.to( device, coronium.IOS, "You have received a new Txtpire message", "+1", "beep.caf")
As I said, the problem is receiving the messages when the app is running. When I first start the app, it will run the refresh once automatically and again for any notifications that were received previously. I can see the error messages through the debug console via xcode/device, but the Runtime listener isn’t called
What I want to happen is that refresh is called when a new push is received. Right now that isn’t happening.
main.lua (setup the initial connection with pushbots)
local pushbots = require("mod\_pushbots") local notifications = require( "plugin.notifications" ) notifications.registerForPushNotifications() local function notificationListener( event ) if event.type == "remoteRegistration" then -- This device has just been registered for push notifications. -- Store the Registration ID that was assigned to this application. deviceToken = event.token --store the token UserInfo.deviceToken = deviceToken ------------------------------------------------------------ -- PUSHBOTS REGISTRATION ------------------------------------------------------------ pushbots:registerDevice( deviceToken, pushbots.NIL, function(e) if not e.error then if e.code == 200 then pushbots:clearBadgeCount( deviceToken ) end else native.showAlert( "Pushbots", e.error, { "OK" } ) end end) ------------------------------------------------------------ else -- A push notification has just been received. Print it to the log. print("### --- Notification Event ---") --get token deviceToken = UserInfo.deviceToken end end Runtime:addEventListener( "notification", notificationListener ) pushbots:init( PushBotAppID ) -- PushBots App ID pushbots.showStatus = true -- for debuging pushbots.showAlert = true pushbots.showJSON = true
The runtime event listener is canceled before leaving main so that it won’t be a problem in messages
message.lua (for receiving notification that there is an update):
local notifications = require( "plugin.notifications" ) notifications.registerForPushNotifications() local refresh= function(event) print("### --- Notification Event ---") if event then print("Event type", event.type) end -- Reset badge count to 0 pushbots:clearBadgeCount( UserInfo.deviceToken ) counter = counter +1 --mark opened pushbots:pushOpened() tempmessage.text = tostring(counter).." push received" if event then local beep = audio.loadSound("beep.caf") audio.play(beep) end end refresh() Runtime:addEventListener( "notification", refresh )
build.settings and config.lua are correct according to current Corona documentation:
-- build.settings plugins = { -- Push notifications ["plugin.notifications"]= { publisherId = "com.coronalabs" }, } -- config.lua -- Push notifications notification = { iphone = { types = { "badge", "sound", "alert" } }, }
Any suggestions? Ideas??