This document is intended for the average Titanium Developer to enable push notification. It is assumed that the reader already has a basic knowledge of Titanium and the APIs.
There are several steps that you will need to follow to enable Push Notifications in your applications, they are :
Determine which platform you wish to have notifications on. Preferably on both iOS and Android.
Set up your application in Appcelerator Studio.
Become familiar with the Cloud section of the Dashboard.
Register your application with Apple and create all necessary Application Identifiers, Certificates and Provisioning Profiles.
Register your application with Google and set up the Google Developer Console for Google Cloud Services
Implement the code into your application inside a Common JS library.
Determine which platform you wish you have notifications on
The purpose of Titanium is to write one code base that works with multiple platforms. This document will teach you how to set up for both of them. However if you only wish to set up for one platform this document will help you do that as well. The two platforms that will be discussed are iOS and Android. First we will cover iOS setup and then Android.
Set up your application in Appcelerator Studio
You may already have your application created, or you may be starting from scratch. Either way open your project in Appcelerator Studio. Make sure that your application is set up for Appcelerator Services.
You can enable this in two places. First upon creation of the project. Second is from the tiapp.xml file. Open the tiapp.xml and you will see a section called ‘Appcelerator Services’. Click the ‘Enable Appcelerator Services’, then turn on the ‘Cloud’ section. Enabling cloud services in Studio creates a new Cloud application and adds its URL and credentials to the Titanium project.
Then you will see a section called ‘Modules’, this is where new modules can be added. We are going to add the Cloud module (iOS) and the Cloud Push module (Android).
Click the ‘Plus’ icon and you will see this screen. It gives you a list of modules that are available with the current SDK you have installed. For this document we are working on 3.2.1.GA. If you want notifications for iOS add the ti.cloud module. Android you will need to add ti.cloudpush, or add both of them.
Become familiar with the Cloud Section of the Dashboard
Go to the Dashboard at https://dashboard.appcelerator.com/ and enter your Username and Password.
There you will see a bar on top which is the main navigation. Click the ‘Apps’ tab to show a list of apps that you have registered with Appcelerator. Select the app you want to enable push notifications for. Then click the ‘Cloud’ tab, which will load the ACS page.
Note: There are two forms of Cloud Functionality on this Dashboard. Select either Development or Production. If you start with Development make sure you add what you need into Production when you want to distribute the app to either Apple or Google.
Register your application with Apple
- Create an App Identifier
- Create a Push Notifications Certificate
- Create a Provisioning Profile
- Register Certificate with Appcelerator Cloud Services
Step 1: Create an App Identifier
Apple requires you to register your application’s id and create a special certificate to be able to utilize push notifications. You will need to login to the Apple Developer Member Center. Once there you will see a section that looks similar to the one pictured below.
Select ‘Certificates, Identifiers & Profiles’ from this page. Once there select the ‘Identifiers’ folder. Click the + icon on the top right of the page to add a new Identifier. Fill out the form below with the information required. Under the ‘App Services’ section there is a column of checkboxes. Select ‘Push Notifications’ and click ‘Continue’, then ‘Submit’, then ‘Done’.
Note : You cannot use a Wildcard App ID for an app with Push Notifications
Step 2 : Create a Push Notifications Certificate
Go to the Certificates, Identifiers & Profilers. On this page you will need to click the Certificates folder Icon. That will load a screen that lists any certificates that you currently have created. We need a Push Notification certificate so click the + button on the top right.
You will then come to a page asking you “What type of certification do you need?” There are two sections for this called Development or Production. You must decide which kind of certificate you need at this point. Under each section there is a choice called “Apple Push Notification service SSL” .The Development version is just for testing and such. Production will be what you need to send the app to Apple and make it public.
Then you will be asked to create a CSR (Certificate Signing Request). The instructions to do this are listing on the page itself. Follow the instructions and when complete click ‘Continue’.
Now you will need to upload that CSR file. Click ‘Choose File’ and locate the CSR, which has an extension of ‘.certSigningRequest’. Once selected click ‘Generate’
The certificate will be generated and available for you to download. Save it somewhere on your computer. Then open Keychain Access on your computer by either double clicking the Certificate or going to Applications – Keychain Access. Locate the certificate inside Keychain by choosing ‘Certificates’ under the Category section. Find the certificate in that list and right-click/two finger click it. Choose ‘Export’ and you will be prompted to save a .p12 file. Save it to your computer and open your web browser. Go back to the Dashboard and select the ‘Cloud’ tab to continue Push Notification setup.
Choose ‘Settings & Configuration’ and a new page will load containing a tabbed view on it. Select ‘iOS Push’ and you will see a section called ‘Push Certificate’ and an button to add a file. Click that button and find your .p12 file on your computer. Upload the .p12 file and that will allow Appcelerator Cloud Services to communicate with Apple for Push Notifications. If you set a certificate password you must also enter that as well.
Step 3 : Create a Provisioning Profile
Enabling Push Notifications
Go back to the Apple Developer Member Center and click ‘Certificates, Identifiers & Profiles’. Click the + button on the top right of the page.
Then you will need to select what type of profile you need. There are two sections, Development and Distribution. Select the most appropriate one for your project at this time and click ‘Continue’.
Choose your applications id (the app identifier you created earlier) from the drop down list and click ‘Continue’.
Select your certificate that you created and click ‘Continue’.
Now you can choose which devices you want to run the app on. You can pick and choose or just select all.
Now you will need to name the profile. Then click ‘Generate’ and download it. It will save as a ‘.mobileprovision’ file. Double-click that file to install it into Xcode.
Try it and leave a comment below to let us know if you had any problems following these steps.
We will continue next week with part 2 and the following with part 3.