Setting up the uPush module in your android Titanium Project

Report 5 Downloads 60 Views
Setting up the uPush module in your android Titanium Project 1. Unzip the com.upush.push-android-0.1.zip file. 2. Copy the com.upush.push folder and contents to your Titanium android modules directory – this is normally located at /Library/Application Support/Titanium/modules/android 3. If you haven’t already done so, create your Titanium android project. (Note: there have been reports of issues with this module when the first character of the Titanium Application ID is uppercase. This has not been consistently proven, but we recommend ensuring that the first character is a lowercase letter to prevent a possible occurrence of this problem) 4. Open the overview of the tiapp.xml file in your Titanium Android project and click the + button to add a new module

5. Select the com.upush.push module from the list of Android modules and then click OK. (Note uPush is only compatible with Titanium SDK 2.1.2.GA or higher)

6. This should then show the module as added to your project.

7. Open the tiapp.xml file for editing and ensure that the following entries are made: <property name="com.upush.push.gcmsenderid" type="string">734324228924 <property name="com.upush.push.titaniumappid" type="string">co.uk.jtmtechnology.testapp <property name="com.upush.push.titaniumappname" type="string">TestApp

Notes: a) The package property of the android manifest tag (ie this line in the tiapp.xml <manifest package="co.uk.jtmtechnology.testapp" android:versionName="1.0" android:versionCode="1">)

must be set the same as your application id (set in the tag of your tiapp.xml file). b) The uPush property com.upush.push.gcmsenderid must be set to your Google GCM Sender ID (created in section 12a of the document ‘Registering your project for GCM with Google and uPush). c) The uPush property com.upush.push.titaniumappid must be set the same as the as your application id (set in the tag of your tiapp.xml file). d) The uPush propert com.upush.push.titaniumappname must be set the same as you application name (set in the tag of your tiapp.xml file). e) most standard tiapp.xml files will already include the line so if you cut and paste these entries into your tiapp.xml, make sure this line is not duplicated. f) There is a known Titanium bug that causes an ‘Application restart required’ error when opening the application from a received push message. To prevent this error we recommend using Titanium SDK version 2.1.3.GA or higher and including the following code in your Tiapp.xml <property name="ti.android.bug2373.finishfalseroot" type="bool">true As show on the following page in the example tiapp.xml.

Here is an example of a complete tiapp.xml file: <property name="ti.android.bug2373.finishfalseroot" type="bool">true <deployment-targets> false false false true false <sdk-version>2.1.3.GA co.uk.jtmtechnology.testapp TestApp 1.0 alanbrowne http:// <description>not specified 2012 by alanbrowne appicon.png false <prerendered-icon>false <statusbar-style>default <statusbar-hidden>false false false true 9cfd1fb7-f9c3-4e5c-96f1-747a562aa5ed <property name="ti.ui.defaultunit">system <property name="com.upush.push.gcmsenderid" type="string">734324228924 <property name="com.upush.push.titaniumappid" type="string">co.uk.jtmtechnology.testapp <property name="com.upush.push.titaniumappname" type="string">TestApp <modules> <module version="0.1" platform="android">com.upush.push

8. Open your project’s app.js file and add the following code: var upush = require('com.upush.push'); upush.registerUpush ( { success:function(e) { //Successfully Registered //This is the registration id that is required when sending a push message through the uPush Service //You will need to save this registration id to your own server, you only need to save this once var regid = e.registrationId; }, error:function(e) { //An error has occurred during registration Ti.API.info("uPush Registration Error: " + e.error); }, callback:function(e) { //Don't forget to add this line Ti.Android.NotificationManager.cancelAll(); //This is called when a push notification is received when the app is open alert('uPush Notification Received: ' + JSON.stringify(e.data));

} } );

9. That’s it !! 10. The example tiapp.xml and app.js can be found in the example folder of the com.upush.push-android-0.1.zip file.