Need advice, Cant get push notifications cert to work

Hi,

I have tried 5 times to get push certifications to work in itunes but building my test app for notifications just doesn’t work. Nothing happens with device on the phone. I have followed this tut on parse for getting the keys https://parse.com/tutorials/ios-push-notifications and my app really stripped down just to test if something happens. Before this code i used this code from corona labs docs http://docs.coronalabs.com/guide/events/appNotification/index.html but the only thing I got there was that local event.type was nil. Ive tried so many different options but don’t know what else to do :confused: I have tried this code to https://github.com/jlooper/DessertOMeter-GFX2 and a new user is being created on parse but its the same there, the push notifications event is nil.

local function onNotification( event )

   print(“my device id is”,event.token)

    if event.type == “remoteRegistration” then

        if event.token ~= nil then

            --save the deviceToken as a global so we can grab it later

            deviceToken = event.token

        else

            print(“no token returned, too bad”)

        end

    elseif event.type == “remote” then

        native.showAlert( “Hello there”, event.alert , { “OK” } )

   end

end

local notificationListener = function( event )

   native.setProperty( “applicationIconBadgeNumber”, 0 )

end

– The notification Runtime listener should be handled from within “main.lua”

Runtime:addEventListener( “notification”, onNotification )

config.lua


   application = 

    {

        content =

        {

            width = 360,

            height = 480,

            scale = “letterBox”,

            xAlign = “center”,

            yAlign = “center”,

            imageSuffix = 

            {

                ["@2x"] = 1.5,

                ["@4x"] = 3.0,

            },

        },

        notification = 

        {

            iphone = {

                types = {

                    “badge”, “sound”, “alert”

                }

            }

        }

    }

Push notifications are tough to implement. There are so many points of failure and very little visibility into the issue.

You have to of course have your developer and distribution certificates in order along with the provisioning profiles that has push notifications turned on.

Then you have to have a separate developer and distribution key/certificates as well.  You have to export them just right and upload them just right to your push sending service.

Then you have to make sure if you’re both ends are using sandbox or production servers.

Then of course, we’ve moved push notifications to a plugin recently, so you may need to include the right things in your build.settings and then make you’re own call to register events and such.

As of right now, because of this last point, I’m not sure how much we can help.  We don’t know what version of Corona you’re running.  We don’t now what your build.settings looks like, etc.   If you can provide some more code, we might be able to give you a better answer.

Rob

First of all Thank you Rob, your always there for answers quick, that deserves more than a thank you  :) Im using the latest daily build,  I had no idea about the plugin, its not in the docs http://docs.coronalabs.com/guide/events/appNotification/index.html ? Now I got the notification popup. Do I just continue building on the code as usual from the corona docs linked here or is there something else that has been new/added?

See the plugin documentation:  http://docs.coronalabs.com/daily/plugin/index.html

Also as a daily build user, the latest documentation is always located here:  http://docs.coronalabs.com/daily/

Rob

Finally got some respons using parse, what pain in the *** notifications is, a hole freaking day.  event.applicationState == "active" and  launch args  got it to working. Tomorrow is time for Android  :)  Thanks for the help, much appreciated =)) Here is my code to register the device and to be able to get notifications offline and active.  Its really dirty but works for testing. Some arguments are not needed, like event.error because parse return everything in event.respons so its a useless check. The event.respons shows errors in the simulator. I always use debug console from corona code exchange to se output on the device, help a lot =))

local notifications = require( "plugin.notifications" ) notifications.registerForPushNotifications() local launchArgs = ... if ( launchArgs and launchArgs.notification ) then     print( launchArgs.notification.type )     print( launchArgs.notification.name )     print( launchArgs.notification.sound )     print( launchArgs.notification.alert )     print( launchArgs.notification.badge )     print( launchArgs.notification.applicationState ) end local json = require("json") local mime = require("mime") local debugconsole = require("debug\_console") debugconsole.enableDebugPrint() debugconsole.setBackgroundColor( .94, .94, 1 ) debugconsole.setFontSize( 11 ) debugconsole.setConsoleWidth( display.contentWidth \* 2 ) debugconsole.enableDebugPrintConsole() local deviceToken local function notificationListener( event )         print( "notification engine started!" )       if ( event.type == "remote" and event.applicationState == "active" ) then         --handle the push or local notification         print( "type ", event.type )          print ("event alert ", event.alert )      elseif ( event.type == "remoteRegistration" ) then         local deviceToken = event.token         --local deviceType = 1  --default to iOS         print( "Event Token is" .. " " .. event.token )         local function networkListener( event )         print( "this is the event respons", event.response )             if ( event.isError ) then                 --error occurred                 native.showAlert( "Notification Registration Failed", "An Error Contacting the Server has Occurred.", { "OK" } )         else             --registration successful!                 print( "Parse registration successful", system.getInfo("deviceID") )             end         end             local commands\_json =         {                 --["badge"] = "0",                 ["channels"] = {"goteborg"},                 ["timeZone"] = "Europe/Stockholm", -- does not work                 ["deviceType"] = "ios",                 --["installationId"] = system.getInfo("deviceID"),                 ["deviceToken"] = deviceToken,                 ["appName"] = "test app",  --OR: system.getPreference( "ui", "language" ),                 ["appIdentifier"] = "com.teamhokuspokus.testapp", -- dubbel check!                   }         local post\_body = json.encode( commands\_json )         local headers = {}         headers["X-Parse-Application-Id"] = "Appi-key"         headers["X-Parse-REST-API-Key"] = "rest-api-key"         headers["Content-Type"] = "application/json"         local params = {}         params.headers = headers         params.body = post\_body         network.request ( "https://api.parse.com/1/installations", "POST", networkListener, params )     end end -- The notification Runtime listener should be handled from within "main.lua" native.setProperty( "applicationIconBadgeNumber", 0 ) Runtime:addEventListener( "notification", notificationListener )

Thanks for sharing

Hi again Rob. Im trying to register android device for push notifications on the latest daily build and getting these errors in my logicat. Do you know what they mean? 

02-16 00:10:19.251 W/ActivityManager(  341): Permission denied: checkComponentPermission() owningUid=10069

02-16 00:10:19.251 W/ActivityManager(  341): Permission denied: checkComponentPermission() owningUid=10069

02-16 00:10:19.259 I/Icing   ( 3277): Indexing done 1D973285BA003B7805063D61617A6A52BB245B51

02-16 00:10:19.299 I/Corona  ( 3728): [Lua::RuntimeDispatchEvent()] WARNING: This function is deprecated. Use Lua::DispatchRuntimeEvent() instead.

My build settings are:

android = { usesPermissions = { "android.permission.INTERNET", "android.permission.GET\_ACCOUNTS",             "android.permission.RECEIVE\_BOOT\_COMPLETED",             "com.google.android.c2dm.permission.RECEIVE",             ".permission.C2D\_MESSAGE", }, permissions =         {             { name = ".permission.C2D\_MESSAGE", protectionLevel = "signature" },         }, },    plugins =     {         ["plugin.notifications"] =         {             publisherId = "com.coronalabs"         },         ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },     },   

This is on emulator running android version 4.3 … I get the same error message in logical when installing googlepushnotifications test app that comes with corona sample code.

GCM deprecated some method to register device for receiving push notification in the latest release. so check your plugin code and retry with new api, it will work.

Push notifications are tough to implement. There are so many points of failure and very little visibility into the issue.

You have to of course have your developer and distribution certificates in order along with the provisioning profiles that has push notifications turned on.

Then you have to have a separate developer and distribution key/certificates as well.  You have to export them just right and upload them just right to your push sending service.

Then you have to make sure if you’re both ends are using sandbox or production servers.

Then of course, we’ve moved push notifications to a plugin recently, so you may need to include the right things in your build.settings and then make you’re own call to register events and such.

As of right now, because of this last point, I’m not sure how much we can help.  We don’t know what version of Corona you’re running.  We don’t now what your build.settings looks like, etc.   If you can provide some more code, we might be able to give you a better answer.

Rob

First of all Thank you Rob, your always there for answers quick, that deserves more than a thank you  :) Im using the latest daily build,  I had no idea about the plugin, its not in the docs http://docs.coronalabs.com/guide/events/appNotification/index.html ? Now I got the notification popup. Do I just continue building on the code as usual from the corona docs linked here or is there something else that has been new/added?

See the plugin documentation:  http://docs.coronalabs.com/daily/plugin/index.html

Also as a daily build user, the latest documentation is always located here:  http://docs.coronalabs.com/daily/

Rob

Finally got some respons using parse, what pain in the *** notifications is, a hole freaking day.  event.applicationState == "active" and  launch args  got it to working. Tomorrow is time for Android  :)  Thanks for the help, much appreciated =)) Here is my code to register the device and to be able to get notifications offline and active.  Its really dirty but works for testing. Some arguments are not needed, like event.error because parse return everything in event.respons so its a useless check. The event.respons shows errors in the simulator. I always use debug console from corona code exchange to se output on the device, help a lot =))

local notifications = require( "plugin.notifications" ) notifications.registerForPushNotifications() local launchArgs = ... if ( launchArgs and launchArgs.notification ) then     print( launchArgs.notification.type )     print( launchArgs.notification.name )     print( launchArgs.notification.sound )     print( launchArgs.notification.alert )     print( launchArgs.notification.badge )     print( launchArgs.notification.applicationState ) end local json = require("json") local mime = require("mime") local debugconsole = require("debug\_console") debugconsole.enableDebugPrint() debugconsole.setBackgroundColor( .94, .94, 1 ) debugconsole.setFontSize( 11 ) debugconsole.setConsoleWidth( display.contentWidth \* 2 ) debugconsole.enableDebugPrintConsole() local deviceToken local function notificationListener( event )         print( "notification engine started!" )       if ( event.type == "remote" and event.applicationState == "active" ) then         --handle the push or local notification         print( "type ", event.type )          print ("event alert ", event.alert )      elseif ( event.type == "remoteRegistration" ) then         local deviceToken = event.token         --local deviceType = 1  --default to iOS         print( "Event Token is" .. " " .. event.token )         local function networkListener( event )         print( "this is the event respons", event.response )             if ( event.isError ) then                 --error occurred                 native.showAlert( "Notification Registration Failed", "An Error Contacting the Server has Occurred.", { "OK" } )         else             --registration successful!                 print( "Parse registration successful", system.getInfo("deviceID") )             end         end             local commands\_json =         {                 --["badge"] = "0",                 ["channels"] = {"goteborg"},                 ["timeZone"] = "Europe/Stockholm", -- does not work                 ["deviceType"] = "ios",                 --["installationId"] = system.getInfo("deviceID"),                 ["deviceToken"] = deviceToken,                 ["appName"] = "test app",  --OR: system.getPreference( "ui", "language" ),                 ["appIdentifier"] = "com.teamhokuspokus.testapp", -- dubbel check!                   }         local post\_body = json.encode( commands\_json )         local headers = {}         headers["X-Parse-Application-Id"] = "Appi-key"         headers["X-Parse-REST-API-Key"] = "rest-api-key"         headers["Content-Type"] = "application/json"         local params = {}         params.headers = headers         params.body = post\_body         network.request ( "https://api.parse.com/1/installations", "POST", networkListener, params )     end end -- The notification Runtime listener should be handled from within "main.lua" native.setProperty( "applicationIconBadgeNumber", 0 ) Runtime:addEventListener( "notification", notificationListener )

Thanks for sharing

Hi again Rob. Im trying to register android device for push notifications on the latest daily build and getting these errors in my logicat. Do you know what they mean? 

02-16 00:10:19.251 W/ActivityManager(  341): Permission denied: checkComponentPermission() owningUid=10069

02-16 00:10:19.251 W/ActivityManager(  341): Permission denied: checkComponentPermission() owningUid=10069

02-16 00:10:19.259 I/Icing   ( 3277): Indexing done 1D973285BA003B7805063D61617A6A52BB245B51

02-16 00:10:19.299 I/Corona  ( 3728): [Lua::RuntimeDispatchEvent()] WARNING: This function is deprecated. Use Lua::DispatchRuntimeEvent() instead.

My build settings are:

android = { usesPermissions = { "android.permission.INTERNET", "android.permission.GET\_ACCOUNTS",             "android.permission.RECEIVE\_BOOT\_COMPLETED",             "com.google.android.c2dm.permission.RECEIVE",             ".permission.C2D\_MESSAGE", }, permissions =         {             { name = ".permission.C2D\_MESSAGE", protectionLevel = "signature" },         }, },    plugins =     {         ["plugin.notifications"] =         {             publisherId = "com.coronalabs"         },         ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },     },   

This is on emulator running android version 4.3 … I get the same error message in logical when installing googlepushnotifications test app that comes with corona sample code.

GCM deprecated some method to register device for receiving push notification in the latest release. so check your plugin code and retry with new api, it will work.