Posted on by
NOTE: This tutorial is outdated and has been replaced by the Local/Push Notifications guide. Please refer to this guide for details and usage examples.

Posted by . Thanks for reading...

61 Responses to “Push Notifications for iOS in Corona SDK”

  1. Luke

    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!

    Reply
  2. Joakim

    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!

    Joakim

    Reply
  3. Richard Roberts

    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!!)

    Richard

    Reply
  4. Matt

    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?

    Reply
  5. Rob Miracle

    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…

    Reply
  6. Rodrigo RSCdev

    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!

    Rodrigo.

    Reply
  7. Jonathan Beebe

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

    Reply
  8. Rob Miracle

    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)
    Executable=/Users/rmiracle/Lua/AppBuilds/tACKY.app/tACKY
    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?

    Reply
  9. Jonathan Beebe

    @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).

    Reply
  10. Luke

    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.

    Reply
  11. Andreas Kviby

    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.

    Reply
  12. Rob Miracle

    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?

    Reply
  13. Rob Miracle

    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

    Reply
  14. Rob Miracle

    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.

    Reply
  15. Bedhouin

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

    Reply
  16. Jon Parkins

    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!

    Reply
  17. pmaxim

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

    bye
    pmaxim

    Reply
  18. Can

    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 ?

    Reply
  19. Can

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

    Reply
  20. Haakon

    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”}

    Reply
  21. AbouHaRga

    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

    Reply
  22. Charlie C.

    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!”}}’
    https://go.urbanairship.com/api/push/url:

    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?

    Reply
  23. Lourenco

    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?

    Reply
  24. Tiago

    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?

    Reply
  25. PauloPeresJr

    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.

    Reply
  26. jm

    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.

    Reply
  27. Kiriakos

    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!

    Reply
  28. cb5x

    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.

    Thanks.

    Reply
  29. Rajesh

    Hi,

    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

    Thanks

    Reply
  30. Matt

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

    Reply
  31. Jeff

    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.

    Reply
  32. Jeff

    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.

    Reply
  33. Jeff

    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”},
    “custom”:{“field1″:”value1″,”field2″:”value2″,”field3″:”value3″,”fieldN”:”valueN”}
    }

    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;

    Reply
  34. Derek

    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?

    Reply
  35. pbriz

    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 ?

    Reply
  36. BorgB

    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 []

    Reply
  37. Joseph Saade

    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.

    Reply
  38. Piotr Machowski

    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

    Reply
  39. Laura

    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

    Reply

Leave a Reply

  • (Will Not Be Published)