Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 38
Registered: ‎09-27-2012
My Device: 9930
My Carrier: airtel
Accepted Solution

Push notification in webworks

Hii.,

 

I am developing an app using jquery mobile(web works). It will be really helpfull if someone can help with my doubt.Here is the doubt, is it possible to use push notifications in the bb app developing using jquerymobile. Or whether i need to use any plugin to have the application of push notification.?

Retired
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Push notification in webworks

Yes you can have push notifications in WebWorks. You can find a complete application with examples listed here:

https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/pushCapture

@erikjohnzon
erjohnson@blackberry.com
Developer
Posts: 38
Registered: ‎09-27-2012
My Device: 9930
My Carrier: airtel

Re: Push notification in webworks

Hi erikjohnzon ,

 

I reffered the link that you attached with your reply. Actually i need to develop this app in BlackBerry OS: 5.0 - 7.0. From the link i can understand that it supports BB 10 os only. so is it possible to  have the push notifications in WebWorks in  the  platform  BlackBerry OS: 5.0 - 7.0 ? Hope u understand my query.

Retired
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Push notification in webworks

No worries, yup my mistake we have been so focused on BB10. Here is a link to our docs which actually outline how to do push: -https://developer.blackberry.com/html5/api/blackberry.push.html

 

As you can see it is supported in BB OS5.0+.

 

-Erik

@erikjohnzon
erjohnson@blackberry.com
New Developer
Posts: 2
Registered: ‎01-19-2015
My Device: BlackBerry Z3
My Carrier: 8980019758

Push notification in webworks

Hi there,

 

i was trying to implement push notification for BB10,

 

and also i had downloaded  push service sdk as push initiator with BIS service.

 

And i am using below plugin for client side code as i was developing application with cordova.

 

https://github.com/phonegap-build/PushPlugin.git

 

with this plugin i was able to createChannel successfully but still i was not able to get notification.

 

For referance i had added my client-side code below.

 

Please provide some solution as early as possible.

 

Thants & Regards,

 

index.js

 

var app = {
    initialize: function() {
        this.bindEvents();
    },

    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },

    onDeviceReady: function() {	
		
		// ******* BlackBerry10 ******* 
		function pushNotificationHandler(pushpayload) {
			var contentType = pushpayload.headers["Content-Type"],
				id = pushpayload.id,
				data = pushpayload.data;//blob
			alert(JSON.stringify(pushpayload));
			alert(id);
			alert(data);			
			if (pushpayload.isAcknowledgeRequired) {				
				pushpayload.acknowledge(true);
			}
		};        
		
		function successHandler(result) {
		       alert('<li>success:' + JSON.stringify(result) + '</li>');
		}
		function errorHandler(error) {
		      alert('<li>error:' + JSON.stringify(error) + '</li>');
		}
		function onPushTransportReady(result) {
			if (result == blackberry.push.PushService.SUCCESS) {
						alert("successful Configuration");
				} else {    							
					if (result == blackberry.push.PushService.INTERNAL_ERROR) {
						alert("Error: An internal error occurred while calling launchApplicationOnPush. " + "Try restarting the application.");
					} else if (result == blackberry.push.PushService.CREATE_SESSION_NOT_DONE) {
						alert("Error: Called launchApplicationOnPush without an " +
						"existing session. It usually means a programming error.");
					} else {
						alert("Error: Received error code (" + result + ") after " + "calling launchApplicationOnPush."); 		
					}
				}
		}
		function onSimChange() {
			alert("SIM card is changed!");
		}
		if (localStorage.getItem("regID") === undefined || localStorage.getItem("regID") === null) {
			try {
					pushNotification = window.plugins.pushNotification;
					alert('<li>registering ' + device.platform+' : '+pushNotification + '</li>');
					if (device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos") {
						pushNotification.register(successHandler, errorHandler, {	
							"senderID": "###########",
							"ecb": "onNotification"
						});
					}
					else if (device.platform == 'blackberry10') {
						alert('gone');
						var options = {
						  invokeTargetId: "...",
						  appId: "XXXX-XXX...",
						  ppgUrl: "http://cpXXXX.pushapi.eval.blackberry.com", 
						  ecb: pushNotificationHandler,
						  simChangeCallback: onSimChange,
						  pushTransportReadyCallback: onPushTransportReady,
						  launchApplicationOnPush: true
						}
						pushNotification.register(successHandler, errorHandler,options);
					}
					else {					
						pushNotification.register(tokenHandler,errorHandler,
												  {
												  "badge": "true",
												  "sound": "true",
												  "alert": "true",
												  "ecb": "onNotificationAPN"
											  });
					}
				} catch (err) {
					txt = "There was an error on this page.\n\n";
					txt += "Error description: " + err.message + "\n\n";
					alert(txt);
				}

		} else if (localStorage.getItem("registered") === undefined || localStorage.getItem("registered") === null) {
			//sendRegIdToServer();
		}
		app.receivedEvent('deviceready');
		
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

   config.xml

 

<?xml version='1.0' encoding='utf-8'?>
<widget id="MyPushDemo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:rim="http://www.blackberry.com/ns/widgets">
    <feature name="com.blackberry.utils" />
    <feature name="com.blackberry.push" value="com.blackberry.push" />
    <feature name="com.blackberry.invoked" value="com.blackberry.invoked" />
    <feature name="PushPlugin" value="PushPlugin" />
    <feature name="Device" value="Device" />
    <name>MyPushDemo</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="WebSecurity" value="disable" />
    <rim:permissions>
        <rim:permit>run_when_backgrounded</rim:permit>
        <rim:permit>read_device_identifying_information</rim:permit>
        <rim:permit>post_notification</rim:permit>
        <rim:permit system="true">_sys_use_consumer_push</rim:permit>
        <rim:permit>read_device_identifying_information</rim:permit>
    </rim:permissions>
    <rim:invoke-target id="MypushDemo">
        <type>APPLICATION</type>
        <filter>
            <action>bb.action.PUSH</action>
            <mime-type>application/vnd.push</mime-type>
            <mime-type>text/plain</mime-type>
        </filter>
    </rim:invoke-target>
</widget>

 

New Developer
Posts: 2
Registered: ‎01-19-2015
My Device: BlackBerry Z3
My Carrier: 8980019758

Re: Push notification in webworks

Hi all,

 

Can someone help me out for my previous post.

 

i was stuck for my client side code.

 

:No: