Push notifications not working

hi 

local function onNotification(event)

print(“nagu onNotification”)

   if event.type == “remoteRegistration” then

       – This device has just been registered for push notifications.

       – Store the Registration ID that was assigned to this application by Google or Apple.

       myRegistrationId = event.token

       print(" onNotification=")

       print(event.name)

      inspect(event)

       – Display a message indicating that registration was successful.

       local message = “This app has successfully registered for push notifications.”

       native.showAlert(“Information”, message, { “OK” })

native.showAlert(“Information”, myRegistrationId, { “OK” })

       – Print the registration event to the log.

       print("### — Registration Event —")

       

   else

       – A push notification has just been received. Print it to the log.

       print("### — Notification Event —")

     

   end

 end

 Runtime:addEventListener( “notification”, onNotification )

The above code is not working can any one pls help me out

Made the settings as specified…

Hi @nagarjuna,

What platform are you on, iOS or Android? Did you fully read the guide on notifications?

https://docs.coronalabs.com/guide/events/appNotification/index.html

Best regards,

Brent

Hi brent,

it s for android

Regards,

Nagarjuna

Hi Brent,

The problem s solved now i have moved the code to main.lua file it works fine…

Can u pls let me know any specific reason why the code works only when the code is placed in main file…

Hi Nagarjuna,

Typically, that would be caused by a “scope” issue, where the code is not being recognized or called from the proper place, or inter-related between the module you originally placed it in and main.lua.

Are you completely familiar with the concept of scope? If not, then I suggest you read the following tutorial. Scope is an absolutely essential and fundamental concept in programming, so you should study it carefully before proceeding with your development:

https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

Best regards,

Brent

Thanks Brent

Hi @nagarjuna,

What platform are you on, iOS or Android? Did you fully read the guide on notifications?

https://docs.coronalabs.com/guide/events/appNotification/index.html

Best regards,

Brent

Hi brent,

it s for android

Regards,

Nagarjuna

Hi Brent,

The problem s solved now i have moved the code to main.lua file it works fine…

Can u pls let me know any specific reason why the code works only when the code is placed in main file…

Hi Nagarjuna,

Typically, that would be caused by a “scope” issue, where the code is not being recognized or called from the proper place, or inter-related between the module you originally placed it in and main.lua.

Are you completely familiar with the concept of scope? If not, then I suggest you read the following tutorial. Scope is an absolutely essential and fundamental concept in programming, so you should study it carefully before proceeding with your development:

https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

Best regards,

Brent

Thanks Brent