What are Push Notifications?
Not to be confused with local notifications, which are completely client-side (no server needed), remote push notifications (will refer to them as just “push notifications” from now on) are notifications that are sent from an external server to a specific client device.
Upon receiving a push notification, you’ll have a chance to make your app react accordingly. They are called “push notifications” because your apps never have to “poll” to receive them, they are instead “pushed” directly to the user’s device.
If you want all the technical details, or want to really appreciate how much easier this will be to implement in Corona as opposed to going the native route, feel free to take a look at the official documentation on Push Notifications.
Requirements
There are several requirements you must meet in order to implement push notifications successfully. To complete the steps in this tutorial, you’ll need the following:
- Corona build 2011.711 or later. This will not work on build 2011.707 (in which the feature was first announced).
- An active iOS Developer Program membership (from Apple).
- A server that has PHP installed and supports outgoing socket connections on custom ports (specifically, port 2195). For the sake of this tutorial and learning how to get things up and running, you can use your Mac (that’s connected to the internet) in place of the remote server. When you’re ready for production, however, you’ll most-likely need—at minimum—a virtual private server (VPS) account, as most shared hosting providers (to include “app hosting” services like Google App Engine) do not allow outgoing connections to ports other than 80.
- Minimum Xcode version of 4.2 (due to changes in the way apps are signed).
- An iOS device for testing, to ensure push notifications work (this can’t be tested using the Corona or Xcode simulator).
- Lots of patience, which—as you know—is not unusual when dealing with Apple development certificates and provisioning profiles.
Step 1: Certificate Signing Request (CSR)
In order to create a push-enabled App ID in the Provisioning Portal, you’ll need to apply for a digital certificate. Before you can do that, you need to have a “certificate signing request” (CSR), which is a file you’ll upload to Apple’s servers and they’ll generate the certificate for you to download.
Open the Keychain Access app and navigate to the Keychain Access > Certificate Assistance > Request Certificate from a Certificate Authority… menu option. Ensure no private key is currently selected in the main Keychain Access window or you’ll have problems.
The Certificate Assistant window should pop up. Fill in the fields as you see in the screenshot (below), but substitute you@youremail.com for your own email address.
Ensure the ‘Saved to disk’ option is selected an choose Continue. Save the file to your Desktop as: RemotePush.certSigningRequest
Once the window closes, within the main Keychain Access window, find the private key with the same name you specified in the Certificate Assistant (if you’re following this tutorial exactly, it’ll be called “Remote Push”). Right-click on the private key and choose “Export”. You’ll be asked to set a password—make sure to write this down!
Save the file to your desktop as: RemotePushKey.p12
Step 2: Create an App ID
Go to the iOS Provisioning Portal and click App IDs on the left.
When the page loads, click the New App ID button to the far right.
On the “Create New App ID” page, fill in the fields as you see in the screenshot (below). In the Bundle Seed ID section, choose “Generate New” or “Use Team ID” if you don’t have an option to generate a new one.
When you’re finished, click the Submit button to continue.
You should be taken to the page with a list of all App IDs you have created. Find the one you just created and click the Configure link to the far right of the row.
On that page, click on the checkbox that reads Enable for Apple Push Notification service and then click the Configure button for the “Development Push SSL Certificate”. When you’re ready for production (or Adhoc) builds, you’ll need to go back and follow these same steps for the “Production Push SSL Certificate” as well.
The following window should pop up:
Click the Continue button, upload the RemotePush.certSigningRequest file you saved to your desktop and wait for the page to generate the certificate.
Once it is completed, you’ll have the option to download the file. Save the aps_developer_identity.cer file to your desktop as well.
So by now you should have the following three files all saved to your desktop. I’ll be coming back to them in Step 7, so for now, just leave them alone.
- RemotePush.certSigningRequest (CSR)
- RemotePushKey.p12
- aps_developer_identity.cer
Step 3: Provisioning Profile
Next, we’ll be creating a new provisioning profile that’s associated with the new push-enabled App ID we just created. This is also the provisioning profile you’ll choose in the ‘Build’ window in Corona when that time comes.
This step assumes you already have a certificate set up in the iOS Provisioning Portal as well as a testing device. I highly recommend that you do not attempt to try Push Notifications as one of the first things you do in Corona. I do recommend becoming familiar with the Corona build process, setting up your development provisioning profiles, etc.
So when you’re ready…
Go back to the iOS Provisioning Portal and click Provisioning on the far left.
Click on the New Profile button on the far right and fill in the fields as described below:
- Profile Name: RemotePush (or another name)
- Certificates: Choose your certificate.
- App ID: Choose the App ID you created in Step 2.
- Devices: Choose the device you’ll be testing on.
When you’re finished, click the Submit button. You’ll be taken back to your list of Provisioning Profiles. Wait a few seconds and then refresh the page, a Download button should appear next to the Provisioning Profile you just created. If the Download button is not there, just keep refreshing the page until it does appear.
Once the Download button appears, save the file to a location you can find it (such as your Downloads folder).
Next, you need to install your new Provisioning Profile into Xcode and also on your device. The easiest way to do this is to launch Xcode, and open up the Organizer by pressing Cmd + Shift + 2 on your keyboard.
Plug in the device you’re going to be testing on and wait for the status indicator to turn green. Now is the time to set the device up for development if you haven’t previously done so.
Once your device is ready to go, under the the Library section in the sidebar of the Organizer window, click on Provisioning Profiles. Then, drag your newly created Provisioning Profile into the big white area in the right pane of the organizer window (as shown in the screenshot below). That will install the Provisioning Profile to both Xcode and your device (assuming it’s the same device you checked when you created the profile).
Step 4: Notification Events
Before you actually write any code, I need to explain how things work so you have an understanding of not only what is going on, but also when you should expect certain things to happen.
Once your app is fully set up for Push Notifications, when you launch your app, if you haven’t yet enabled Push Notifications for your app, this is the time you’ll receive the popup asking if you want to allow your app (e.g. “RemotePush”) to receive notifications. If not, then you most-likely built your app using the wrong Provisioning Profile.
The “remoteRegistration” event.type
Once the app has authorization to receive push notifications, a “notification” event will be dispatched with an event.type of “remoteRegistration”. At this time, your app will then contact the Apple Push Notification Service (APNS) and if the provisioning profiles, certificates, etc. are good to go, then you’ll get back a device token. This is a unique string that’s needed for your own server to send push notifications to the specific device that the token is associated with.
Keep in mind that if the device is ever restored (even from a backup), a new token will be assigned to the device, so there are cases where the device token will change.
Receiving a unique “device token” is the whole purpose of the “remoteRegistration” event.type in your notification listener.
For the sake of this tutorial, we’re going to have a native alert show the device token, and you’ll simply copy it down manually for later use in the server script. The purpose of this is so you can get a feel for how push notifications work, how they are sent, and so you can easily program in what will happen when your app does receive a push notification.
When your app is ready for production, you obviously won’t be copying down all of your users’ device tokens manually and plugging it into a script. Instead, during the “remoteRegistration” event.type, you’ll most-likely take the device token and send it to your script remotely as an URL variable, or in a POST body of an HTTP request.
The “remote” event.type
When your app receives a push notification, a “notification” event will be dispatched if your app is in the foreground, or if it is suspended. Apps that are completely closed are a little different, but I’ll get into that in a moment.
The event table for a remote push notification—accessed from your notification listener—will have the following properties:
- event.type - “remote”
- event.name - “notification”
- event.sound - “string representing sound file, or ‘default’”
- event.alert - “string representing alert message”
- event.badge - “badge count if sent”
- event.applicationState - “active” or “inactive” (depending on if the app was in the foreground or suspended)
Notifications from Cold Start
If your app is completely closed (e.g. not in the foreground, but not suspended), then remote push notifications are handled in a similar manner to local notifications.
You will set up a variable at the very top of your main.lua file that’s assigned the value of “…”. If your app is launched as a result of the user viewing a remote Push Notification, then the variable will contain a “notification” table.
Here’s an example main.lua file:
local launchArgs = ...
if launchArgs and launchArgs.notification then
--[[ notification table contains:
launchArgs.notification.type - "remote"
launchArgs.notification.name - "notification"
launchArgs.notification.sound - "sound file or 'default'"
launchArgs.notification.alert - "message specified during push"
launchArgs.notification.badge - "5" -- badge value that was sent
launchArgs.notification.applicationstate - "inactive"
--]]
end
In the example above, launchArgs.notification will only exist if the app is launched as a result of a user responding to a push notification.
Still with me?
This step was more “FYI”, so you can understand what will be going on during the next steps. So you’re right in thinking that it wasn’t an actual “step”, but you should definitely understand everything that was discussed before moving on.
So by now you should understand that:
- Your server must have the unique device token for every device it sends a push notification to.
- The device token is received during the “remoteRegistration” event.type of your notification listener (it is your responsibility to pass this to the script on your server, but for the sake of this tutorial we will be copying it into the script manually).
- When your server sends a push notification, if the app is in the foreground or suspended, it will receive a notification event with an event.type of “remote”.
- If your app is completely closed and the user responds to a push notification that was sent for your app, then instead of a notification event, the launchArgs table (if defined in main.lua) will have a “notification” table attached with all the data associated with the notification.
So if all of the above is clear to you, then congratulations, you’re ready to move onto the next step!
Step 5: Your Corona Project
The first thing you need to do is make sure a specific table is included within your config.lua file. You can simply copy/paste from the example, but ensure that the ‘notification’ table is within the ‘application’ table, not the ‘content’ table.
config.lua
application =
{
content =
{
width = 320,
height = 480
},
notification =
{
iphone =
{
types =
{
"badge", "sound", "alert"
}
}
}
}
The presence of a ‘notification’ table in your config.lua is what will trigger the “Do you wish to allow ‘Your App’ to receive Push Notifications?” popup when the user first launches your app.
Next, we’re going to create a main.lua file that is very simple. It’s going to be set up to receive “notification” events, and also be prepared to receive a notification table through a launchArgs table.
main.lua
local launchArgs = ...
local json = require "json"
if launchArgs and launchArgs.notification then
native.showAlert( "launchArgs", json.encode( launchArgs.notification ), { "OK" } )
end
-- notification listener
local function onNotification( event )
if event.type == "remoteRegistration" then
native.showAlert( "remoteRegistration", event.token, { "OK" } )
elseif event.type == "remote" then
native.showAlert( "remote", json.encode( event ), { "OK" } )
end
end
Runtime:addEventListener( "notification", onNotification )
The notification listener will display a native alert with the device token every time an event.type of “remoteRegistration” is dispatched (every time the app is launched).
If the app receives a notification event with an event.type of “remote”, the app will simply show a native alert with the event table serialized into a JSON string so you can see the notification details.
The app will do a similar thing if launched from a cold start in response to a push notification that was received (via launchArgs.notification table).
Step 6: Copy Your Device Token
Start a new Corona project, and copy/paste the config.lua and main.lua code from the examples. Build using the push-enabled provisioning profile and install the app onto your device.
Launch the app. You should see a native alert pop up with your device token. Copy down the (rather lengthy) device token because you’ll need it when we set up the push notification script. Once again, you’re only copying this down manually for the sake of this tutorial (e.g. during development).
It’s worth saying again: When your app is ready for production, you’ll want to handle device tokens in a more automated fashion, most-likely by sending it directly to a script on your server to send a notification right away, or store the device token in a database so a notification can be scheduled to be sent later on (the possibilities are nearly endless).
Step 7: Combining Your Certificate and Key
Next, we’re going to use the files we generated in the first couple of steps to make even more files, and then combine two of those files to produce a single .pem file which will be used by the script we’ll use to send push notifications.
The .pem file that we’re going to generate is a combination of your “Push Notification Developer Identity Certificate” and the private key you exported earlier. This file is needed for your server to communicate securely with the APNS (which is what actually sends the push notification to your device).
This step involves a lot of command-line work, so please double or triple-check what you type to ensure the .pem file is generated properly.
If you’ve been using different filenames than the one’s I’ve used in the example, please substitute the filenames with the ones you used. Pay close attention to how some filenames end with “Key” and others end with “Cert”, those differences are very important.
Open up a terminal and “cd” to your desktop (~/Desktop):
$ cd ~/Desktop
Convert the .cer file into a .pem file:
$ openssl x509 -in aps_developer_identity.cer -inform der
-out RemotePushCert.pem
Convert the private key’s .p12 file into a .pem file:
$ openssl pkcs12 -nocerts -out RemotePushKey.pem -in RemotePushKey.p12
Enter Import Password:
MAC verified OK
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
As you can see from the example above, you’ll be asked for the password you set for your private key earlier, and also be asked to set a “passphrase” for the final .pem file. Make sure you remember this passphrase or you won’t be able to send push notifications from your server!
Lastly, you need to combine the certificate and key into a .pem file—this is the one your server will use to authenticate push requests to APNS:
$ cat RemotePushCert.pem RemotePushKey.pem > ck.pem
If you followed the commands above, the important file to take from all these steps is ck.pem. The other files you can now move into a directory and backup somewhere safe.
Step 8: The PHP Script
I’m going to give you a PHP script that has everything that is required for sending a push notification from a remote server. It is a very basic use-case scenario, however, and requires that you manually include the device token for the device you wish to send a push notification to.
This script is not meant to be used in production as-is, but can be used as a reference to know how to send push notifications. Most likely, the “real” script you’ll use on your server will take in URL or POST variables for the device token, and have some method of scheduling notifications (but that’s all up to you, and the needs of your app).
Here’s the code for the PHP script. Create a new folder somewhere, open up a blank text file, and copy/paste the following code into it. Save this file as sendpush.php:
NOTE: If you cannot see the code above, please go here to view it.
Be sure to put your device token and ck.pem passphrase into the appropriate places in the script above (in between the single quotes). Also notice the section where it says “// Create the payload body”. This is where you’ll place push notification specific parameters such as alert, sound, badge, launchImage, etc. It’s worth noting that the “payload body” cannot exceed 256 bytes (which is about the size of a tweet), or the push notification will be rejected.
Now, take the ck.pem and copy it into the same folder as sendpush.php.
Open up a terminal into the folder with sendpush.php and you should be able to send a push notification to your device (that has the app installed) by typing:
$ php sendpush.php
If all goes well, you should see the following message:
Message successfully delivered
A few moments later, if you had the app installed and followed all previous steps correctly, you should receive the push notification on your device. Congratulations! You have successfully prepared your Corona project to receive push notifications.
The next step on your part is making the script more robust, so that it can take in device tokens in a more automated fashion, and figure out how and when you want push notifications delivered. Other than that, you have everything you need to send push notifications from a remote server!
Production Considerations
When you’re ready for production, you’ll want to make sure you remove “sandbox” from the URL (in the PHP script) on the line that reads:
ssl://gateway.sandbox.push.apple.com:2195
The “sandbox” basically indicates that you’re sending a test notification. Real “production” notifications are sent to: ssl://gateway.push.apple.com:2195
Another thing to keep in mind is that production certificates expire in one year from their creation date, so you’ll want to make sure to go through the second half of Step 2 (where you generate the aps_developer_identity.cer file from the RemotePush.certSigningRequest file) and also redo all the command-line steps to create a new ck.pem file before your certificate expires.
If you wait too long, your users may have down time in regards to push notifications, and may even experience crashes depending on how heavily your app relies on the push notifications.
Additionally, you’ll need to configure your App ID for Production before you create your Ad-hoc or Distribution provisioning profiles or your app will not be able to receive push notifications properly.
Conclusion… Finally.
That was A LOT to take in, I know. Probably more-so than you expected if you’ve had no prior experience with push notifications in iOS. It’s also no surprise that the shortest part of the tutorial was the things you actually do on the Corona-side of things.
If you’re confused, it’s worth reading over again slowly, step-by-step and try building the sample that I walked you through in the tutorial (rather than trying to implement it in your own app at first). That way you gain a better understanding of how things work and the implementation details. Then, you should try implementing it into your app.
Also remember, only subscribers have this feature available as of Daily Build 2011.711, so if you’re not a subscriber and want to take advantage of Push Notifications and a bunch of other features that aren’t available to the public just yet, become a subscriber today.




Sunny
T-H-A-N-K Y-O-U !
OnTouch
At last, thank you JB !!!!
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!
Joe
Is Urban Airship for push supported or do we have to run our own server?
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
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
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?
christian mueller
thx…
and now lets do widgets for android….
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…
Tatum
Thank you JB!!!
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.
Jonathan Beebe
For those asking about EasyAPNS, it looks like commenter Luke has tried it and says it’s working fine for him
Brad Herman
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
https://developer.anscamobile.com/forum/2011/03/15/push-notifications?page=1&destination=
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?
Richard Roberts
I just tried the tuto by Jonathan and it works perfectly.
Thanks for the clear instructions Jonathan.
Richard
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).
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.
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.
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?
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
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.
Bedhouin
As usual…. How long for Android? Is it in the pipeline or is it going to be the same story as maps?
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!
pmaxim
Thank you.
I did not have json component in my php server, but after I installed it all worked very well.
bye
pmaxim
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 ?
Can
event.type == “remoteRegistration” triggers when push notifications off in device settings menu! Why?
Can
Custom Alert Sounds ?
Incubar
Any ETA on push notifications for Android
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”}
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
leonardo
Hi. Thanks Carlos. I tested today and work fine.
Best regards
Leonardo
IvalueLabs – Costa Rica
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?
eng_dev
this link doesn’t work
Jen Looper
Charlie, did you ever get this to work? Share code please?
Glen
What about Android push notifications? So much for multi platform.
brangerbriz
Agree with Haakon. event.custom is always empty. Without this is impossible to use the push notification in a good app.
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?
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?
PauloPeresJr
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
p.peresjr@gmail.com
Free of charge.
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.
eng_dev
Any news about push notifications for Android yet ????
pbriz
any workaround for custom data in push notification ?
Joe Flowers
FYI – badges don’t show if you don’t have a valid icon (as I didn’t when first testing this)
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.
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!
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.
Brent Sorrentino
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.
http://developer.coronalabs.com/release/2012/996/
Thanks,
Brent Sorrentino
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
Matt
How would you retrieve the custom data? I’ve tried launchArgs.notification.custom but its empty. Latest build.
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.
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.
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;
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?
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 ?
kamlesh
hey great tutorial thank u sir
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 []