![]() |
CloudBuilder C++ SDK
v3.0.0
Making social games is easy !
|
First, setup a certificate with Push notification enabled on Apple Developer Center
Download it,
and convert it to .pem format with the following command :
You'll also need to convert the private key used to generate this certificate to the .pem format. To do this, you first need to export your private key to p12 format by using the Keychain Access tool on your Mac. Launch Keychain Access and right click on the certificate that you have just downloaded and installed, and select the "Export" option, and then the .p12 format.
Once this is done, just convert your private key to .pem format with the following command:
Once you've got your two .pem files, open a web page to your Back Office web page, tick the iOS box inside the the "Push Notification Certificates" in your Status page, and fill respectively the "Certificate" and "Private Key" cells with the contents of the files you just created at the previous step (see above).
Finally, a little piece of code is needed in your AppDelegate.mm file :
In case you need some more information about how Google Cloud Messaging works, please have a look at the official Google documentation. Otherwise, by following the steps below, you should be able to have your application manage push notifications pretty quickly.
First, you need to setup a Google Application. Since this is changing quite rapidly at the time of writing, please follow the previous guide for information on how to do it. Once this is done, this Google Application needs to reference the Google Cloud Messaging for Android API. This is done from the APIs section of the Google Developer Console for your project.
In case you are using the new interface, it may look more like the following capture. In this case, when following the instructions above, follow the page add Cloud Messaging to your existing app and click on the button "Get a configuration file". Then you need to input information about your application (remember to sign in with your Google Developer account first). In the next screen you will obtain everything needed to set up GCM: the API key to set in the backoffice and the sender ID to set in the manifest.
Next step is to create a Public API key. To do so, select the Credentials section, just below the APIs section in the previous step, scroll down to the bottom of the page, and click the "Create new Key" button for the Public API access list of keys. Then select "Server key" option, and then "Create", not modifying anything. You should now have a new, valid API key.
Once this is done, you're almost finished with parameterization, and only some bits of code will be needed. But first, you need to declare your Google Application with Clan of the Cloud through your Back Office web page. Now it's straightforward. Just tick the Android box inside the "Push Notification Certificates" in your Status page, and fill the "senderID" cell with the Google Application project number, and the "apiKey" cell with the key you just created at the previous step (see above).
Now everything's been done on the Google Application side, we need to add a few snippets of code, so your application can communicate with the Google Cloud Messaging servers. First thing to modify is your AndroidManifest.xml, which is located under Assets/Plugins/Android. Add the following permissions to your manifest.
Also add the following line to your manifest under the application node. Replace the value with your GCM sender ID.
Also under the application node, add the following entries:
You also need to implement a service on your own, that will listen for and handle push notifications. As such, you will need an entry such as the following under the application node.
The class may (minimalistically) look like follows, but you are free to customize it to your liking.
That's it, you're done and can now begin to send push notifications to your Android application!