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

BlackBerry Push Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 82
Registered: ‎09-26-2012
My Device: Torch 9800
My Carrier: NA

onInvoke not getting called in push development

[ Edited ]

Hi,

 

I am creating an app using bbui which has push notifications.

I created a sample app and also ran the push capture sample provided by bb. Both the app works fine. But when i integrate the code in my app. I am able to create a callbackchannel but not able to receive the messages.

 

I am using require.js and backbone in my app

 

Notification = Backbone.Model.extend({
		startNotification:function(){
			notification=this;
			createTable(createNotificationStatement);
			alert("startNotification");
			var ops = { invokeTargetId :'myb.pushreceiver.invoke.push', 
					appId :'XXX-1234rftgtyhmm7t97no8a168ijsdjsXXsdmsd6', 
					ppgUrl :'http://pushapi.na.blackberry.com' };

			try {
				alert(blackberry.push);
				blackberry.push.PushService.create(ops, 
						this.successCallback, 
						this.failCallback, 
						this.simChangeCallback, 
						this.pushTransportReadyCallback);
			} catch (err) {
				alert(err);
				console.log("Create was called more than once with different " 
						+ "values for options.invokeTargetId or options.appId.");
				
			}


		},
		successCallback:function(pushService1) {
			pushService = pushService1;
			alert("pushService"+pushService);
			alert("SUCCESS Of CREATE");
			
			try{
				pushService.createChannel(notification.createChannelCallback);
			}
			catch(e){
				alert("in create successcallback catch::"+e);
			}	   
		},
		 onInvoke: function(invokeRequest) {
		 	alert('In on invoke');
			if (invokeRequest.action != null && invokeRequest.action == "bb.action.PUSH") {
				alert("IN invokeRequest action.PUSH");
				   if (pushService != null) {          
				  	   var pushPayload =  pushService.extractPushPayload(invokeRequest); 
					   if (pushPayload.isAcknowledgeRequired) {
						   
						   pushPayload.acknowledge(true);
						}				
			           notification.pushNotificationHandler(pushPayload);
				   }
				
			   }
		},
		createChannelCallback : function(result, token) {
			alert("createChannelCallback")
			if (result === blackberry.push.PushService.SUCCESS) {
				alert("SUCCESS Of createChannelCallback")
				alert(token);
				alert('Adding Listener');
				try{
				blackberry.event.addEventListener("invoked", onInvoke);
				}
				catch(e){
					alert("error calling event::"+e)
				}
			}}

 Where am i going wrong?

 

Regards,

Annuk

Retired
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10
My Carrier: Rogers

Re: onInvoke not getting called in push development

Hi Annuk,

 

A couple of things:

1. I would advise against calling createChannel on every startup of your app.  It has an overhead associated with it and, typically, once the channel is created it doesn't need to be recreated.  (The BIS PPG might unsubscribe the user if they haven't received a successful push for 60 days, so creating a channel once a month might be advisable.)

2. You should call launchApplicationOnPush with a value of true before doing a create channel.  Otherwise, if your app is closed and a push comes in, it will not receive it.

3. I would register your event listener for the "invoked" event earlier after a successful call to blackberry.push.PushService.create rather than waiting for a successful create channel call.

 

Hope this helps,

 

Matt

Developer
Posts: 172
Registered: ‎05-01-2010
My Device: Z10
My Carrier: O2

Re: onInvoke not getting called in push development

I think the ppgUrl is wrong. isnt it? According to the API reference it should be http://cpXXX.pushapi.na.blackberry.com

 

 



----------------------------------------------------------
find my widgets -> http://blackberry.itbert.de
Highlighted
Retired
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10
My Carrier: Rogers

Re: onInvoke not getting called in push development

Yes, the PPG URL now includes the content provider ID part "cpXXX".