-
17 Oct 2012 4:01 AM #1
Answered: Sencha command not accepting PhoneGap functions
Answered: Sencha command not accepting PhoneGap functions
Hi,
I'm packaging my app using PhoneGap and I use the 'sencha app build package' command to build the code for the package.
The problem that I'm facing is that as soon as I put some PhoneGap code, the sencha command refuses to build it.
<code>
init: function() {
console.log('Login');
if(Ext.browser.is.PhoneGap){
navigator.notification.alert('Its Alive!');
}
},
</code>
As soon as I comment the navigator line, it builds.
Otherwise it throws an error saying TypeError 'undefined' is not an object
-
Best Answer Posted by estesbubba
I ran into the same problem and ended up writing a native controller and the code only runs when PhoneGap fires the deviceready event. This controller fires events that other native controllers can listen to like the PushNotification controller. SDK tools is happy doing it this way and our code is cleaner.
Code:Ext.define('Csg.ebpp.controller.Native', { extend: 'Ext.app.Controller', requires: [ ], config: { }, init: function() { var me = this; document.addEventListener('deviceready', function() {me.onNativeLaunch()}, false); }, onNativeLaunch: function() { var me = this; Csg.isNative = true; console.log('Ajax endpoint: ' + Csg.appRoot); cordova.exec(null, null, "SplashScreen", "hide", []); me.getApplication().fireEvent('nativeLaunch'); document.addEventListener('resume', function() {me.onResume()}, false); }, onResume: function() { var me = this, accountData = Ext.decode(sessionStorage.getItem('accountData')); console.log(accountData); if (accountData) { me.getApplication().fireEvent('validateSession', Ext.emptyFn, me); } me.getApplication().fireEvent('nativeResume'); } });
-
17 Oct 2012 6:14 AM #2
I ran into the same problem and ended up writing a native controller and the code only runs when PhoneGap fires the deviceready event. This controller fires events that other native controllers can listen to like the PushNotification controller. SDK tools is happy doing it this way and our code is cleaner.
Code:Ext.define('Csg.ebpp.controller.Native', { extend: 'Ext.app.Controller', requires: [ ], config: { }, init: function() { var me = this; document.addEventListener('deviceready', function() {me.onNativeLaunch()}, false); }, onNativeLaunch: function() { var me = this; Csg.isNative = true; console.log('Ajax endpoint: ' + Csg.appRoot); cordova.exec(null, null, "SplashScreen", "hide", []); me.getApplication().fireEvent('nativeLaunch'); document.addEventListener('resume', function() {me.onResume()}, false); }, onResume: function() { var me = this, accountData = Ext.decode(sessionStorage.getItem('accountData')); console.log(accountData); if (accountData) { me.getApplication().fireEvent('validateSession', Ext.emptyFn, me); } me.getApplication().fireEvent('nativeResume'); } });
-
17 Oct 2012 9:03 PM #3
It worked!!
Thanks a lot man. I was stuck here for a very long time.


Reply With Quote