简体   繁体   中英

Integrate sencha touch 2 into phonegap, cannot get 'deviceready' event to fire up

This seems to be another issue than PhoneGap 0.9.6 (Blackberry) + Sencha Touch 1.1.0: deviceready does not fire it's related to iOS.

So, I can't get that event to fire up; using latest cordova (phonegap) 1.6.1.

Has anyone been successfully integrating these ST2 and PhoneGap?

Here's my app.json :

"js": [
    {   
        "path": "resources/js/cordova-1.6.1.js",
        "update": "delta"
    },
    {
        "path": "sdk/sencha-touch.js"
    },
    {
        "path": "app.js",
        "update": "delta"
    },
],

My app.js:

launch: function() {
    // Destroy the #appLoadingIndicator element
    Ext.fly('appLoadingIndicator').destroy();
    var mainPanel = Ext.Viewport.add({
        xclass: 'Sencha.view.Main'
    });

    // load phonegap stuff
    document.addEventListener("deviceready", function () {
        mainPanel.fireEvent("deviceready");
    } , true);
},

My Main.js controller :

Ext.define('Sencha.controller.Main', {
    extend: 'Ext.app.Controller',
    
config: {
    refs: {
        mainPanel: 'mainpanel',
    },
    control: {
        mainpanel: {
            deviceready: 'onDeviceReady'
        },
    },
},
onDeviceReady: function() {
    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.NONE]     = 'No network connection';
    Ext.Msg.alert('Connection type', states[networkState], Ext.emptyFn);
    navigator.notification.beep(2);
},

Sencha Touch 2 will listen to that event and call your onReady/launch methods - therefore if you try listening to them in the launch method, it has already been fired.

Just put your logic inside the launch method in your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM