Push Notifications for iOS in Corona SDK

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0

NOTE: This tutorial is outdated and has been replaced by the Local/Push Notifications guide.

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0

This entry has 61 replies

  1. Sunny says:

    T-H-A-N-K Y-O-U !

  2. OnTouch says:

    At last, thank you JB !!!!

  3. Luke says:

    I tried the PHP example above and it was sending the payload but it wasn’t turning up on my device.

    I then used the PHP class by EasyAPNS and it works perfectly! weird…

    Great work!

  4. Joe says:

    Is Urban Airship for push supported or do we have to run our own server?

  5. Joakim says:

    Woaww, so theres no need for a third party service like urban ship to send push notifications? As i have my own server it would be ten times easier to implement this!


  6. Jonathan,

    An excellent read. The length is so inconsequential once you start and before you know it you’ve already read it through. It really gets the old creative juices going!

    I just submitted my very first app yesterday to the app store and very much enjoyed reading this blog today.

    I can’t wait to get home from work and try it out.

    Thanks for your continued support (and a shout out to Peach!!)


  7. Matt says:

    Can we use EasyAPNS php or Urban Airship’s interface… I am good with every part of this but trying to figure out the saving of the token etc since manually entering it would not work for production app. This looks awesome… I’m guessing if you had multiple apps running push that you would need separate php pages sending the messages and handling the reading of the tokens?

  8. christian mueller says:

    and now lets do widgets for android…. 🙂

  9. Rob Miracle says:

    If you’re not that PHP friendly on the web hosting side, there is a pre-built package called EasyAPNS (Google it). It provides you a PHP class, a driver PHP script and some samples. It guides you through setting up a MySQL database to track device registrations and queue up messages to send.

    If you’re running a WordPress site and you want to have a push notification sent every time you publish a new post, there is an EasyAPNS plugin that even takes care of the database bits for you.

    Of course I don’t have any of this working yet since I was waiting on this wonderful blog post. (Thanks Jonathan and Ansca!!!). I’ll report more as I head down the EasyAPNS route…

  10. Tatum says:

    Thank you JB!!!

  11. Hey Jonathan and Ansca Staff – Thank you very much! 🙂

    @Robmiracle – Thank you very much for sharing this info!! I have no idea of configuring PHP server, etc…so I run a wordpress blog as well…will look forward your info about that and PLEASE, if you can, after you setup this push-notification into any of your apps, tell me the steps to get it please.

    Thanks in advance!


  12. Jonathan Beebe says:

    For those asking about EasyAPNS, it looks like commenter Luke has tried it and says it’s working fine for him 🙂

  13. Brad Herman says:

    There is a forum post I made about Urban Airship and some looking into it that I did.
    Long Story short, it’s almost possible to use Urban Airship right now, we are missing the “PUT” feature in the corona network request API


  14. Rob Miracle says:

    I tried this and I’m running into a little problem, and its most likely on my key generation end. The first app I’m trying to put this in is my RSS reader app for my son’s music blog. So all the PHP stuff aside I built my app, put it on the phone and ran it. I did not get any of the push notification popups.

    I did get an error after the build was this:

    warning: Application failed codesign verification. The signature was invalid, or it was not signed with an iPhone Distribution Certificate. (-19011)
    codesign_wrapper-0.7.10: using Apple CA for profile evaluation

    I’m going back into the provisioning portal and see if I can delete and restart. I wish I could delete appsID’s. When I first created the tACKY app, I gave it a bundle ID of com.omnigeekmedia.apps.tacky with the grand concept of separating my apps from my games but inMobi couldn’t handle that, so I created a new one com.omnigeekmedia.tacky and unfortunately you can’t really see which one you’re getting in the Apple website interface.

    But would this code signing problem prevent me from getting the initial “this app wants to do push notification” alert?

  15. I just tried the tuto by Jonathan and it works perfectly.

    Thanks for the clear instructions Jonathan.


  16. Jonathan Beebe says:

    @Rob Miracle: Please ensure that if you’re using an Adhoc or Distribution provisioning profile, that your App ID is configured for Push Notifications for Distribution (Adhoc is considered a distribution profile as well).

    Also, on the App ID page, if you click ‘Configure’ on the right, it will show you the rest of the App ID (to help with your problem of not being able to distinguish between the two).

  17. Luke says:

    I have managed to get the following working:

    1) The above example running off the given PHP code.
    2) The above example running off easyAPNS PHP class

    Both examples are running off a Linux VPS server. For some reason I couldn’t get the above example to run in production mode, only worked with my sandbox certificate. This is probably something to do with me rushing the set-up of the provision file or something.

    I’m going to write my own PHP class with mySQL support for a project I’m working on but will be willing to share if anyone finds it of interest.

  18. I just got Push Notifications working together with Urban Airship and it works like a charm. i will share all my code as soon as possible to all you guys and girls that wants to work with Urban Airship.

  19. Rob Miracle says:

    I’ll try that, I’d rather be using an adHoc to test with anyway. Seems I only need the development profiles when leak testing using instruments, but since the example above is using development, shouldn’t I get that to work too?

  20. Rob Miracle says:

    I really shouldn’t try and read this stuff at 11:30 at night. I was getting this with development versions, so I thought, but the error certainly makes it look like I was trying to use a distribution profile.

    Let me go back and make sure

  21. Rob Miracle says:

    Well I have some progress. My app came up and asked if I wanted push notifications. I got my insansly long device token. Updated sendpush.php with my device token and after a Christmas eve chat with my hosting provider, my PHP script said it sent the message, but it never arrived at my device (and I verified the token…)

    BTW: Taking a screen shot of the device with the token dialog up is a good way to capture that information!!!

    Right now I think my biggest problem with this whole process is that when I go to generate the certificate request in the first step, it never shows up in my Keychain Access key list. I got it to work once. Since they (almost) never show up, I can’t right click on it to generate the .p12 file. So I’m using the one I got succesfully created for my adhoc/production side. I’d rather be testing in the sandbox…

    But progress none-the less.

  22. Bedhouin says:

    As usual…. How long for Android? Is it in the pipeline or is it going to be the same story as maps?

  23. Jon Parkins says:

    I’m interested in what you did to get it going with Urban Airship when you get around to it Andreas! We don’t have the capability for server stuff and this would be a great option now that the support is finally there in Corona!

  24. pmaxim says:

    Thank you.
    I did not have json component in my php server, but after I installed it all worked very well.


  25. Can says:

    We have a intro video on my game, but Push Notification alert covers this video for the first opening. How can fire the push notification event manualy. for example when in main menu. I think that its about config.lua and fires automatically.
    If I cant do that, I will pause video while user response push alert.
    But what happens if devices push settings is off ?

  26. Can says:

    event.type == “remoteRegistration” triggers when push notifications off in device settings menu! Why?

  27. Can says:

    Custom Alert Sounds ?

  28. Incubar says:

    Any ETA on push notifications for Android

  29. Haakon says:

    Hi, it seems like you are stripping away custom fields from the payload? You should not, it is an important piece in this kind of communication to be able to do something usefull when the user enters the app via a push notification. It is possible in other mobile frameworks, so please get this implemented asap. Here is an example of a message sent to apple, where everything is showing up in corona except for the custom field. We’re using Urban Airship, and they support custom fields, so it is stripped away in Corona it seems:

    {“aps”: {“badge”: 1, “alert”: “Hello”, “sound”: “default”}, “device_tokens”: [“xxx”], “custom_field”: “custom_value”}

  30. AbouHaRga says:

    Nice article

    but what about if i want to send to more than one device
    how can i modify the php file to send to more than one device

  31. leonardo says:

    Hi. Thanks Carlos. I tested today and work fine.

    Best regards

    IvalueLabs – Costa Rica

  32. Charlie C. says:

    I want to push a message to the Urban Airship server written in Lua such as the example below in Curl:

    -X POST -u “:”
    -H “Content-Type: application/json”
    –data ‘{“device_tokens”: [“”], “aps”: {“alert”: “Hello!”}}’

    Basically is it possible to have a button in a Corona app push code like above to a sever and then the server, Urban Airship for example, in turn will broadcast the message?

    • eng_dev says:

      this link doesn’t work 🙁

    • Jen Looper says:

      Charlie, did you ever get this to work? Share code please?

  33. Glen says:

    What about Android push notifications? So much for multi platform.

  34. brangerbriz says:

    Agree with Haakon. event.custom is always empty. Without this is impossible to use the push notification in a good app.

  35. Lourenco says:

    Thank you Jonathan for this in depth tutorial.

    I managed to get it working and that’s great.

    One thing I noticed : in Step 3: Provisioning Profile
    The profile must be a ‘Development Provisioning Profiles’
    I tried by creating a ‘Distribution Provisioning Profiles’ but it does not work.

    Can someone explain the difference between these 2 profiles?

  36. Tiago says:

    event.custom is definitely coming empty which renders Push Notification almost useless. How are we supposed to let the app know what to do with the event received?

  37. PauloPeresJr says:

    hello guys i made a php system with sql server to recive the tokens and send message.
    if any one want it e-mail me at
    Free of charge.

  38. PauloPeresJr says:

    Jonathan Beebe i’d like to know if you allow me to translate your tutorial to Portuguese giving you the credits.
    Couse i want to make a tutorial of the system i made. And you tutorial wold be perfect to make the start of the mine.

  39. eng_dev says:

    Any news about push notifications for Android yet ????

  40. pbriz says:

    any workaround for custom data in push notification ?

  41. Joe Flowers says:

    FYI – badges don’t show if you don’t have a valid icon (as I didn’t when first testing this)

  42. jm says:

    Does anyone have any idea how to do automatic incrementation of badges.

    I tried saving the recent badge in a databas, then adding it up to the latest badge value I get from the push notification and then updated the badge value of the app.

    But the value that always displays on my app icon is always the badge value that I sent.

  43. Kiriakos says:

    You should really integrate with a 3rd party.
    I used http://www.pushwoosh.com/ in a phonegap project and I had notifications working in less than 30 minutes.

    It would be nice to have the option to use such a service in corona as well (or you could create your own !!!!)
    I don’t mind paying 20$ a month instead of doing all the above programming, plus they give you the option to send notifications from their website directly to your users!

  44. cb5x says:

    Is there an update on the status of custom data being stripped from the push notification. Without the custom data field, Push Notifications are pretty useless.

    Can someone from Corona please comment.


    • Brent Sorrentino says:

      Hi @cb5x,
      We added custom data support to iOS push notifications in daily build #996… and custom data support in Google Push Notifications as well.


      Brent Sorrentino

  45. Rajesh says:


    i am working on apple push notification and i want to send request through proxy so i getting error on both mode production and sandbox..

    //$ctx = stream_context_create();
    $ctx = stream_context_create(array(‘http’ => array(‘proxy’ => PROXY_URL , ‘request_fulluri’ => true)));
    stream_context_set_option($ctx, ‘ssl’, ‘local_cert’, CERTIFICATE_PATH);
    stream_context_set_option($ctx, ‘ssl’, ‘passphrase’, $passphrase);

    // Open a connection to the APNS server
    $fp = stream_socket_client(‘ssl://’.NOTIFICATION_URL.’:2195′, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

    but not working ….. sorry for bad english


  46. Matt says:

    How would you retrieve the custom data? I’ve tried launchArgs.notification.custom but its empty. Latest build.

  47. Jeff says:

    Is there a way to tell via Corona if the user has disallowed remote notifications? We want to be able to tell the user that they are not getting the full value of the app if they do not allow them. But as far as I can tell once they say no to that prompt its not going to come up again. Would be nice to be able to periodically check and remind them that they should really allow them.

  48. Jeff says:

    Does anyone have custom field working yet? It’s still blank (coming through as []) for me using build 1007.

    Can’t look up the related bug #19819 because tracker seems to be down.

  49. Jeff says:

    Finally figured this out. Here’s the solution if anyone needs to know still.

    When you build your json message the custom data is at the SAME LEVEL as aps – NOT WITHIN IT and is itself a json object just like aps.

    So its NOT LIKE this:

    {“aps”: {“badge”: 1, “alert”: “Hello”, “sound”: “default”}, “device_tokens”: [“xxx”], “custom_field”: “custom_value”}

    BUT like this:

    “aps”: {“badge”: 1, “alert”: “Hello”, “sound”: “default”},

    So in PHP it get built as:

    // Create the payload body
    $body[‘aps’] = array(
    ‘badge’ => 0,
    ‘alert’ => $alert,
    ‘sound’ => ‘default’
    $body[‘custom’] = array(
    ‘field1’ => ‘value1’,
    ‘field2’ => ‘value2’,
    ‘field3’ => ‘value3’,
    ‘field4’ => ‘valueN’

    // Encode the whole payload as JSON
    $payload = json_encode($body);

    // Build the binary notification
    $msg = chr(0).pack(‘n’, 32) .pack(‘H*’, $deviceToken) . pack(‘n’, strlen($payload)) . $payload;

  50. Derek says:

    I’m new to Corona, and I’m doing some preliminary research. Could someone explain to me why a PHP based server is required for push notifications, and if its possible at all to do so with a Java based server, and if so, what would be required?

  51. pbriz says:

    Custom variables in Push Notification still doesn’t work. I used the suggestion by Jeff but it seems it doesn’t make any change neither. The notification arrived fine but event.custom is empty. Any clue ?

  52. kamlesh says:

    hey great tutorial thank u sir

  53. BorgB says:

    Also having problems with the custom part of the notifications with corona cloud. Any updates or info on this? Same thing as pbriz has, the notification works, the movedata works, but the event.custom is empty. just a []

  54. Joseph Saade says:

    I think there is something wrong in this tutorial.
    The p12 generation should be done after you get the .cer from apple then export that as a p12.

  55. Push Notification with cloud is a pain. I have spent tremendous amount of time figuring out the proper way to handle iOS Push Notifications and I succeeded to make it in elegant way with Parse.com as a backend.

    I thought some of you guys might want to save long hours of testing so I packet everything up for you: CoronaSDK iOS Push Notifications

  56. Laura says:

    Where did this article go? It was here yesterday. I want the link to the php file that shows how to send a notification to Apple. :S

  57. Marble68 says:

    I know it has been replaced, but I would like to see this code, too.. T learn.