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

Reply
Regular Contributor
annuk
Posts: 82
Registered: ‎09-26-2012
My Device: Torch 9800

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
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

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
bert2002
Posts: 172
Registered: ‎05-01-2010
My Device: Z10

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
Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: onInvoke not getting called in push development

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