-
A BlackBerry 10 device and the appropriate keys that you get from BlackBerry when registering your application.
- Register to evaluate the Push Service. This registration will allow you to test your application in a test environment.
- Register to launch your application in production.
<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>
<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>
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>
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();