Skip to content

Instantly share code, notes, and snippets.

@pec1985
Last active January 1, 2016 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pec1985/8ad59783cd5b4adc45a2 to your computer and use it in GitHub Desktop.
Save pec1985/8ad59783cd5b4adc45a2 to your computer and use it in GitHub Desktop.
Documentation for Push Notifications on BlackBerry 10 Ti SDK

Ti BB10 Push Notifcations

Requirements:

tiapp.xml Configuration:

Required Properties:

<property name="ti.bb.invoke.target.key.push" type="string">{app id}.invoke.push</property>
<property name="ti.bb.invoke.target.key.open" type="string">{app id}.invoke.open</property>
<property name="push_title" type="string">"Some Title, typically the app name"</property>

Required Permissions:

<permission system="true">run_native</permission>
<permission system="true">_sys_use_consumer_push</permission>
<permission>post_notification</permission>
<permission>access_shared</permission>
<permission>read_device_identifying_information</permission>

Required tags

<invoke-target id="{app id}.invoke.push">
  <type>APPLICATION</type>
  <filter>
     <action>bb.action.PUSH</action>
     <mime-type>application/vnd.push</mime-type>
  </filter>
</invoke-target>
<invoke-target id="{app id}.invoke.open">
  <type>APPLICATION</type>
  <filter>
     <action>bb.action.OPEN</action>
     <mime-type>text/plain</mime-type>
  </filter>
</invoke-target>

Conclusion:

This is what the tiapp.xml must look like after placing these tags. Remember to replace {app id} with your app id (com.company.appname)

<property name="ti.bb.invoke.target.key.push" type="string">{app id}.invoke.push</property>
<property name="ti.bb.invoke.target.key.open" type="string">{app id}.invoke.open</property>
<property name="push_title" type="string">App Name</property>
<blackberry>
    <permission system="true">run_native</permission>
    <permission system="true">_sys_use_consumer_push</permission>
    <permission>post_notification</permission>
    <permission>access_shared</permission>
    <permission>read_device_identifying_information</permission>
    <invoke-target id="{app id}.invoke.push">
      <type>APPLICATION</type>
      <filter>
         <action>bb.action.PUSH</action>
         <mime-type>application/vnd.push</mime-type>
      </filter>
    </invoke-target>
    <invoke-target id="{app id}.invoke.open">
      <type>APPLICATION</type>
      <filter>
         <action>bb.action.OPEN</action>
         <mime-type>text/plain</mime-type>
      </filter>
    </invoke-target>
</blackberry>

Usage

Once the properies are correctly setup in tiapp.xml, Place this code in your app, it must be executed sometime at the beginning of the life of the app. To test push notification, use this test page that I have created, make sure the credentials match the email you received from Blackberry when registering for push:
BB Push Notification Test Page - Use the credentials from the Server Configuration Details section of the email received from BlackBerry.
The token of the app will be received from the onChannelCreated callback.

// Credentials are from the _Client Configuration Details_ section of the
// email received from BlackBerry
var win = Ti.UI.createWindow();

Ti.BlackBerry.createPushService({
	appId: '4427-7h6l37627mrr0I3956a74om7643M17l7921',
	ppgUrl: 'http://cp4427.pushapi.eval.blackberry.com',
	usePublicPpg: true,
	launchApplicationOnPush: true,
	onSessionCreated: function(e) {
		Ti.API.info('------------------');
		Ti.API.info('Session Created');
		Ti.API.info('------------------');
	},
	onChannelCreated: function(e) {
		Ti.API.info('------------------');
		Ti.API.info('Channel Created');
		Ti.API.info('Message: ' + e.message);
		Ti.API.info('Token: ' + e.token);
		Ti.API.info('------------------');
	},
	onPushReceived: function(e) {
		Ti.API.info('------------------');
		Ti.API.info('Push Received');
		Ti.API.info('Id: ' + e.pushId);
		Ti.API.info('PayloadId: ' + e.payloadId);
		Ti.API.info('Data: ' + e.data);
		Ti.API.info('------------------');
		e.source.removeAllPushes();
	},
	onConfigError: function(e) {
		Ti.API.info('------------------');
		Ti.API.info('CONFIG ERROR');
		Ti.API.info('Title: ' + e.errorTitle);
		Ti.API.info('Msg: ' + e.errorMessage);
		Ti.API.info('------------------');
		Ti.UI.createAlertDialog({
			title: e.errorTitle,
			message: e.errorMessage
		}).show()
	},
	onError: function(e) {
		Ti.API.info('------------------');
		Ti.API.info('ERROR');
		Ti.API.info('Title: ' + e.errorTitle);
		Ti.API.info('Msg: ' + e.errorMessage);
		Ti.API.info('------------------');
		Ti.UI.createAlertDialog({
			title: e.errorTitle,
			message: e.errorMessage
		}).show()
	},
	onAppOpened: function(e) {
		Ti.API.info('------------------');
		Ti.API.info('App Opened Recieved');
		Ti.API.info('PushId: ' + e.pushId);
		Ti.API.info('PayloadId: ' + e.payloadId);
		Ti.API.info('Data: ' + e.data);
		Ti.API.info('------------------');
		e.source.removePush(e.pushId);
	}
});

win.open(); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment