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
Developer
Posts: 82
Registered: ‎09-26-2012
My Device: Torch 9800
My Carrier: NA

blackberry.push.openBISPushListener gives Argument is not nullable

[ Edited ]

Hi ,

 

I am trying to register my device to blackberry server using:

 

blackberry.push.openBISPushListener(ops, this.onData, this.onRegister, this.onSimChange);

 

But i get the following error: Argument is not nullable

 

My code is as follows:

 

registerForNotifications : function() {

            try {
                var ops = {
                    port : NotificationConstants.bbPort,
                    appId : NotificationConstants.bbAppId,
                    serverUrl : NotificationConstants.bbServerUrl,
                    wakeUpPage : 'push.htm',
                    maxQueueCap : NotificationConstants.bbMax
                    
                    
                };
                
                console.log("BB PORT "+NotificationConstants.bbPort)
                blackberry.push.openBISPushListener(ops, this.onData, this.onRegister, this.onSimChange);
            } catch (err) {
                alert('openBisError ' + err);
            }
       

 

Where am i going wrong?

Thanks in advance.

 

Annuk.

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

Re: blackberry.push.openBISPushListener gives Argument is not nullable

It's hard to say from the sample code you posted but you should double check all the ops and callbacks you are providing to the API are not null.

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

Re: blackberry.push.openBISPushListener gives Argument is not nullable

[ Edited ]

Hi,

checked the call backs they are workng.

 

Find the js file code:

 

 

define(["jquery", "underscore", "backbone", "text!views/template/homepage.html", "collection/notifications","collection/NotificationConstants"], function($, _, Backbone, HomepageTemplate, Notifications,NotificationConstants) {

	var HomepageView = Backbone.View.extend({

		id : "homepage",

		template : _.template(HomepageTemplate),

		initialize : function() {
			console.log('Initializing Homepageview....');
			//	_.bindAll(this, 'render');
			//this.render();
		},

		events : {
			'click  #add' : 'addNotifications',
			'click  #view' : 'viewNotifications',
			'click #register' : 'registerForNotifications'
		},
		render : function() {
			console.log('Rendering Homepageview')
			$(this.el).html(this.template());
			return this;
		},

		addNotifications : function() {
			console.log('Adding notifications to DB');

			var messageData = $("#message").val();
			console.log('messageData ' + messageData);
			var data = JSON.parse(messageData);
			var entity = data.entity;
			var message = data.data;
			
			console.log('Entity is '+entity +" and message is "+message);
			
			var db = openDatabase('mydb', '1.0', 'Notifications DB', 2 * 1024 * 1024);
			db.transaction(function(tx) {
				console.log('Creating table..');
				tx.executeSql('CREATE TABLE IF NOT EXISTS NOTIFICATIONS (id INTEGER PRIMARY KEY AUTOINCREMENT, entity, message, isRead)');
				tx.executeSql('INSERT INTO NOTIFICATIONS (entity, message, isRead) VALUES ('+entity+','+message+',"N")');
			});

		},

		viewNotifications : function() {

			console.log("in View Notifications.Get From DB");
			var db = openDatabase('mydb', '1.0', 'Notifications DB', 2 * 1024 * 1024);
			db.transaction(function(tx) {
				console.log('Fetching rows ');
				notificationsArray = new Array();
				tx.executeSql('SELECT * FROM NOTIFICATIONS', [], function(tx, results) {
					var len = results.rows.length, i;
					console.log('Found rows: ' + len);
					for ( i = 0; i < len; i++) {

						var notes = {};

						notes.id = results.rows.item(i).id;
						notes.message = results.rows.item(i).message;
						notes.entity = results.rows.item(i).entity;
						notes.isRead = results.rows.item(i).isRead;

						console.log(notes.id + " " + notes.message);
						notificationsArray[i] = notes;

					}
					$(this.el).remove();
					console.log("BEFORE ROUTING");
					router.navigate("#notifications", true);
				}, null);
				var router = require("router/router");

			});

		},

		registerForNotifications : function() {

			try {
				var ops = {
					port : NotificationConstants.bbPort,
					appId : NotificationConstants.bbAppId,
					serverUrl : NotificationConstants.bbServerUrl,
					wakeUpPage : 'template/notifications.html',
					maxQueueCap : NotificationConstants.bbMax
					
					
				};
			}
			catch(err)
			{
				alert('OPTIONS--- '+err);
			}
				try
				{
				console.log("BB PORT "+NotificationConstants.bbPort + " ops -- "+ops.wakeUpPage)
				/*
				var data = '{"entity":"points","data":"You earned 145 points yesterday.The current balance is 390 points"}'
								this.onData(JSON.parse(data));*/
				
				blackberry.push.openBISPushListener(ops, this.onData, this.onRegister, this.onSimChange);
			} catch (err) {
				alert('openBisError ' + err);
			}
		},

		onRegister : function onRegister(status) {
			if (status == 0) {
				alert("Successfully registered");
				this.viewNotifications();
			} else if (status == 1) {
				alert("network error");
			} else if (status == 2) {
				alert("rejected by server");
			} else if (status == 3) {
				alert("invalid parameters");
			} else if (status == -1) {
				alert("general error");
			} else {
				alert("unknown status");
			}
		},

		onData : function onData(data) {
			try {
				/*
				alert(blackberry.utils.blobToString(data.payload));
								var response = JSON.parse(blackberry.utils.blobToString(data.payload));*/
				var response = JSON.stringify(data);
				
				console.log('Response '+data);
				var entity = data.entity;
				var message = data.data;
				console.log('Entity '+entity +' message '+message);

				var db = openDatabase('mydb', '1.0', 'Notifications DB', 2 * 1024 * 1024);
				db.transaction(function(tx) {
					console.log('Creating table..');
					tx.executeSql('CREATE TABLE IF NOT EXISTS NOTIFICATIONS (id INTEGER PRIMARY KEY AUTOINCREMENT, entity, message, isRead)');
					tx.executeSql('INSERT INTO NOTIFICATIONS (entity, message, isRead) VALUES (\''+entity+'\',\''+message+'\',"N")');
				});
				
				this.viewNotifications();
				return 0;
				//indicate acceptance of payload for reliable push
			} catch (err) {
				alert('ondata error ' + err);
			}
		},

		onSimChange : function onSimChange() {
			alert("SIM card is changed!");

		},

		unsubscribe : function unsubscribe() {
			//stop listening for pushed data, a clean up step
			blackberry.push.closePushListener(port);
			alert("Push listening has stopped");
		}
	});

	return HomepageView;
});

Is it the wakepage parameter mandatory or optional. I have given the wakeup page as index.html.

 

 Regards,

Annuk

 

 

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

Re: blackberry.push.openBISPushListener gives Argument is not nullable

You should specify a wake up page because your app will be launched with a push comes in and its not currently running.

 

In terms of your code are you sure the ops parameter is not null when you call openBISPushListener? I am not a JavaScript expert but I notice the variable is declared in the try scope so perhaps it is not visible outside of that?

 

I would recommend you double check all your ops (I don't know where the NotificationConstants you have are declared) and all the backbacks to make sure they are not null just before you make the call to openBISPushListener

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

Re: blackberry.push.openBISPushListener gives Argument is not nullable

Hi,

 

Thanks for your reply.

 

I checked all the call back functions. They are working.

Notification Constants are also avaialble in the ops.

All the ops are also avialble.

Had a log for printing the values of the ops.

 

Regards,

Annuk