Languages

Menu
Sites
Language
Notifications and the Tizen Object

I was trying to implement notification in my app, but kept running into "TypeError: 'undefined' is not an object." I looked around made sure i had all of the proper privileges and I believe I do. During testing, I wired up sending a notification to the menu button (tizenkwkey). What I noticed is that it always worked on the first page of my application. As soon as I navigate away from that page, it only works every other time. What's going?

Thanks in advance!

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

4 Replies
Lakshmi Grandhi
Can you please eloborate your query in more detail. What i understood is that notification is working in first page only when you navigate deeper to page 2 or page 3 its not working is that correct. Can you please share your code to check the issue, you need to define menu for page or page 3 for notification object.
Johnny Moralez
Below is the code I'm using for posting the notification. This is located in a menu.js file that is loaded in main.js through the $.getScript(...). I also have a single index.html page that contains the first page, the initial page loaded during start up, where this always works. When navigating to the second page, then it only works every other time. The first time I press the menu button, it will say throw the TypeError, the second time it will actually post the notification, the third time it goes back to TypeError, and so on.
$.getScript('./js/app.js')
	.done(function() {
		// once the app is loaded, create the app object
		// and load the libraries
		app = new App();
		self.loadLibs();
	})
	.fail(this.onGetScriptError);

loadLibs: function loadLibs() {
	var loadedLibs = 0;
	if ($.isArray(app.requires)) {
		$.each(app.requires, function (index, filename) {
			$.getScript(filename)
				.done(function () {
					loadedLibs += 1;
					if (loadedLibs >= app.requires.length) {
						// All dependencies are loaded - initialize the app
						app.init();
					}
				})
				.fail(this.onGetScriptError);
		})
	}
}
function postNotification() {
	console.log("main.js --- postNotification() - Enter / Trying to post a notification");
	try {
		var appControl = new tizen.ApplicationControl(
				"http://tizen.org/appcontrol/operation/create_content",
				null,
				"image/jpg",
				null);
		var notificationDict = {
				content : "This is a simple notification.",
				iconPath : "img/ic_home.jpg", 
				vibration : true, 
				appControl : appControl};
		var notification = new tizen.StatusNotification("SIMPLE", 
				"Simple notification", notificationDict);

		tizen.notification.post(notification);

	} catch (err) {
		console.log (err.name + ": " + err.message);
	}
}

$(document).on('tizenhwkey', function(e) {
	if (e.originalEvent.keyName === "back") {
		if (location.hash === '' || location.hash === '#upcoming_page') {
			tizen.application.getCurrentApplication().exit();
		} else {
			$.mobile.back();
		}
	} else if (e.originalEvent.keyName === "menu") {
		console.log("Menu button pressed");
		openSettingsMenu(location.hash);
		postNotification();
	}
});
Lakshmi Grandhi
Hi, I tried a sample code showing notification for each menu press event as stated in your code. Its working fine, can you test the code by commenting the line "openSettingMenu". I guess there is some issue in this method.
Johnny Moralez
Thank you so much! That's where the issue was. Not sure what's going on there, but that's another problem to handle. The notifications work great now. Thanks again!