Latest Appcelerator Titanium Alloy JPUSH Push Notification Module – iOS and Android, China Push Notification- NON GCM

As you may know Chinese Android phones do not ship with the Google Play store – thus Google Cloud Messaging does not work.

If you are creating a Android Application or a version of your APP for the Chinese market it would be best if you use a Chinese Push Service like JPUSH.

You can sign up at https://www.jpush.cn/

I wrote a JPUSH Module for Titanium Alloy iOS and ANDROID to be able to use the Chinese JPUSH Service. As this was alot of work I am asking for a small donation to be able to download the compiled and ready to use version of my JPUSH Titanium Alloy iOS and Android Modules.

**** THIS MODULE IS PROVIDED WITHOUT ANY FORM OF SUPPORT ****

CLICK HERE TO DONATE AND DOWNLOAD THE JPUSH TITANIUM ALLOY ANDROID MODULE

Once you donate you will receive an email with instructions on how to download the module – if you do not please let me know!

## INSTALLATION

1. Installation

  1. Extract the JPUSH_MODULES.zip you received after your donation.
  2. Move Zips to root of your Application

2. Register your module with your application by editingtiapp.xml and adding your module.

<modules>
	<module platform="iphone">cn.jpush.ti</module>
	<module platform="android">cn.jpush.ti</module>
</modules>

3. Add the Following Like to you tiapp.xml file to prevent Android Crashing

<property name="ti.android.bug2373.finishfalseroot" type="bool">true</property>

4. You Will also need to change the the YOURAPPID below to your app ID found on JPUSH

Android Location: modules/android/cn.jpush.to/VERSION/timodule.xml

<meta-data android:name="JPUSH_APPKEY" android:value="YOUR-JPUSH-APPID-GOES-HERE"/>

iOS Location: modules/iphone/cn.jpush.to/VERSION/platform/iphone/PushConfig.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>APP_KEY</key>
	<string>YOUR_APP_KEY_STRING</string>
	<key>APS_FOR_PRODUCTION</key>
	<string>0</string>
	<key>CHANNEL</key>
	<string>Push channel</string>
</dict>
</plist>

 

5. Place the following code if you app.js file to catch the Push Notification and display it via a POPUP in your app

//////////////////////////////////////////////////////////////////////////////
//				Start Push Section			//

// START IF - iOS ELSE Android
if (Ti.Platform.name == 'iPhone OS'){
	
	// REQUIRE JPUSH MODULE
	var JPush = require('cn.jpush.ti');
			
	// START FUNCTION - registerForPush
	function registerForPush() {
		Ti.Network.registerForPushNotifications({
			success: deviceTokenSuccess,
			error: deviceTokenError,
			callback: receivePush
		});
	             
	    // Remove event listener once registered for push notifications
	    Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush); 
	};
	 // END FUNCTION - registerForPush
	 
	// ADD Eventlistener to Wait for user settings to be registered before registering for push notifications
	Ti.App.iOS.addEventListener('usernotificationsettings', registerForPush);
	
	// START JPUSH - with callback getRegistrationID
	JPush.start(JPushLoginSuccess);
		
	// START FUNCTION - callback to store JPushID
	function JPushLoginSuccess(JPushID){
		Ti.API.log("JPushLoginSuccess - JPushID: " + JPushID);
		
		// run JPushID set data after 2 second delay
		setTimeout(function(){	

			// set JPushID to Ti.App.Properties	
			Ti.App.Properties.setString('JPushID',JPushID);
			
			// run addJPushGroup() after JPushLoginSuccess		
			addJPushGroup();
	
		}, 2000);
			
	};	
	// END FUNCTION - callback to store JPushID
	
	// Start Function - deviceTokenSuccess
	function deviceTokenSuccess(e) {
		
		Ti.API.log("Register with deviceToken: " + e.deviceToken);
		JPush.registerDeviceToken(e.deviceToken);
		    
	};
	// End Function - deviceTokenSuccess
	
	// Start Function - deviceTokenError
	function deviceTokenError(e) {
		Ti.API.log("Failed to Find Token" + e.error);
	};
	// End Function - deviceTokenError
	
	// START FUNCTION - receivePush for iOS
	function receivePush(e) {			
		
		// Ti.API.info Raw Payload
		Ti.API.info("Received Push:" + JSON.stringify(e));  
			
		// JSON.parse payload
		var pushNotification = e;
		// Set Values
		var pushData =  pushNotification.data;
		// send pushData to JPush to log Push received	
		JPush.pushReceived(pushData);
				
		// setTimeout of 500miliseconds and then run pushPopUp function with params
		setTimeout(function(){
			// YOUR CUSTOM POPUP ALERT HERE
			// USING DATA YOU CAN EXTRACT OUT OF pushData
		},500); 
		 
	};
	// END FUNCTION - receivePush for iOS
	
// ELSE IF - Android only
}else if (Ti.Platform.name == 'android'){
	
	// REQUIRE JPUSH MOFULE
	var JPush = require('cn.jpush.ti');	
	
	// ADD EVENTLISTENTER AND FUNCTION TO MODULE
	JPush.addEventListener('JPushLoginSuccess',function(evt){
		
		Ti.API.log("JPushLoginSuccess - JPushID: " + evt.registrationID);
		
		// set JPushID to Ti.App.Properties	
		Ti.App.Properties.setString('JPushID',evt.registrationID);
		
		// run addJPushGroup() after JPushLoginSuccess		
		addJPushGroup();
		
	});	
	
	// ADD EVENTLISTENTER AND FUNCTION TO MODULE
	JPush.addEventListener('pushCallBack',function(evt){
         
		// Set pushNotification as evt
		var pushNotification = evt; 
		// Set pushExtras and JSON.parse into Object
		var pushData = JSON.parse(evt);
    
    	// setTimeout of 500miliseconds and then run pushPopUp function with params
		setTimeout(function(){
			// YOUR CUSTOM POPUP ALERT HERE
			// USING DATA YOU CAN EXTRACT OUT OF pushData
		},500); 
		
    });


};
// END IF - Android Only

///////////////////////////////////////////////////////////////////////////////////////////
// 			START FUNCTION TO ADD TO JPUSH GROUP   				//

// START FUNCTION - addJPushGroup
function addJPushGroup(){
	
	// firstClear groups
	var clearTags = [];						
	JPush.setTags(clearTags);
	
	// set tagsToSet in Array
	var tagsToSet = [];
	tagsToSet.push("highUsage");	

	Ti.API.log("JPush.setTags: " + tagsToSet);
	
	// SET JPush tags
	JPush.setTags(tagsToSet);
	
};
// END FUNCTION - addJPushGroup
// 		END FUNCTION TO ADD TO JPUSH GROUP   	    			 //
///////////////////////////////////////////////////////////////////////////////////////////


If you would like the Source of the Module to add features and compile on your own let me know and I can provide it to you as well.

If you would not like to pay for the module and have a good reason like being a non-profit let me know in the comments and I can provide you with a copy for free.

Let me know if you need any help.

Appcelerator Titanium Alloy JPUSH Push Notification Module – iOS and Android, China Push Notification- NON GCM
Tagged on:                                                                         

Leave a Reply

Your email address will not be published. Required fields are marked *

14 thoughts on “Appcelerator Titanium Alloy JPUSH Push Notification Module – iOS and Android, China Push Notification- NON GCM