PDA

View Full Version : iOS push notification with Sencha Touch, PhoneGap and UrbanAirship



nmadrane
29 Feb 2012, 1:47 AM
I am trying to integrate push notification to my Sencha Touch 1.x application, from the code found at https://github.com/urbanairship/ios-phonegap-plugin.

They provide a sample based on a pure HTML5 application, combining phonegap and urbanairship.

The problem is that nothing is working when I try to follow their steps for my sencha touch application. In order to isolate the problem, I just want to make sure that the plugin is correctly recognized from sencha. For this purpose I am just trying to call the 'log' function of the phonegap plugin which is supposed to display a log message in the XCode console screen. Here are the relevant pieces of code :

In index.html :

<body onload="onBodyLoad()" >
....
</body>

In a js file :

function onBodyLoad() {


document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
window.plugins.pushNotification.log("TEST MESSAGE");
}

var PushNotification = function() {


}


// use this to log from JS to the Xcode console - useful!
PushNotification.prototype.log = function(message) {
PhoneGap.exec(null, null, "PushNotification", "log", [{"msg":message,}]);
};


PhoneGap.addConstructor(function()
{
if(!window.plugins)
{
window.plugins = {};
}
window.plugins.pushNotification = new PushNotification();
});

The text TEST MESSAGE is never displayed so I think there may be a problem with the registration of the phonegap plugin. Here is what the documentation of the plugin says. I followed all the steps.


Integrating the Urban Airship Plugin into Your App-------------------------------------------------- 1) Copy the sample AppDelegate.h/m files from the sample into your project (they replace the autogenerated files) 2) Include PushNotification.js in your WWW folder (check the comments for usage) 3) Add PushNotification.h/m in the Plugins folder 4) Add key "pushnotification" and value "PushNotification" (case-sensitive) to the plugins list in PhoneGap.plist 5) Include the sample index.html or just use the parts you want

mitchellsimoens
29 Feb 2012, 8:01 AM
Does this work without ST loaded?

nmadrane
3 Mar 2012, 1:14 AM
Actually the onDeviceReady is never called !! If I put an alert inside onBodyLoad, the alert appears. When I put an alert inside oneviceReady, nothing appears.

Does anybody know what could be the problem with document.addEventListener("deviceready", onDeviceReady, false) and why the event handler is never called ?

Regards,

Nabil.

ayandyan
21 Mar 2012, 8:05 PM
Make sure you are using the ios version for phonegap-[version].js as the android phonegap js file is also different.



Actually the onDeviceReady is never called !! If I put an alert inside onBodyLoad, the alert appears. When I put an alert inside oneviceReady, nothing appears.

Does anybody know what could be the problem with document.addEventListener("deviceready", onDeviceReady, false) and why the event handler is never called ?

Regards,

Nabil.

swathi001
27 Jul 2012, 10:22 PM
Because document.addEventListener("deviceready", onDeviceReady, false) mostly works in device ..