1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    19
    Vote Rating
    0
    abbysingh is on a distinguished road

      0  

    Default 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

  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');
        }
    
    
    });

  3. #2
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    555
    Answers
    8
    Vote Rating
    24
    estesbubba will become famous soon enough estesbubba will become famous soon enough

      0  

    Default


    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');
        }
    
    
    });

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    19
    Vote Rating
    0
    abbysingh is on a distinguished road

      0  

    Default


    It worked!!

    Thanks a lot man. I was stuck here for a very long time.