Sencha touch 确保在Sencha加载程序之前加载phonegap和插件

Sencha touch 确保在Sencha加载程序之前加载phonegap和插件,sencha-touch,sencha-touch-2,cordova,phonegap-plugins,Sencha Touch,Sencha Touch 2,Cordova,Phonegap Plugins,我已经在Sencha Touch 2.1中编写了一个应用程序,我将其中的一个包嵌入到Cordova/PhoneGap 2.5.0中,并在xCode中编译以在iOS模拟器/iOS上运行。我已将该插件添加到PhoneGap,并为Sencha构建了自己的PhoneGap/SQLite代理,我在我的一些商店中使用了该代理。* 问题:当我将一个内置包嵌入PhoneGap并在iOS模拟器中运行时,我发现在Sencha初始化之前,Cordova不会加载。我之所以看到这一点,是因为我在Sencha应用程序中对代

我已经在Sencha Touch 2.1中编写了一个应用程序,我将其中的一个包嵌入到Cordova/PhoneGap 2.5.0中,并在xCode中编译以在iOS模拟器/iOS上运行。我已将该插件添加到PhoneGap,并为Sencha构建了自己的PhoneGap/SQLite代理,我在我的一些商店中使用了该代理。*

问题:当我将一个内置包嵌入PhoneGap并在iOS模拟器中运行时,我发现在Sencha初始化之前,Cordova不会加载。我之所以看到这一点,是因为我在Sencha应用程序中对代理初始化中调用的
Cordova.exec
导致错误,告诉我找不到
Cordova
对象

我确实成功地在我的应用程序的后面使用了
Cordova.exec
来运行诸如PhoneGap的Childbrowser插件之类的东西,而且它是有效的。但是在应用程序执行的早期阶段,即初始化阶段,使用
Cordova.exec
太早了,无法保证Cordova对象已经实例化

已经尝试过:我已经尝试过以下方法:

  • 我试着简单地将Sencha应用程序的开发者版本嵌入到PhoneGap中。尽管这样做有效,但我不想将我的开发构建部署为我发布的应用程序,因为它效率低下且占用大量空间。然而,我从这个实验中了解到,Sencha Touch微加载器在封装和生产上的工作方式在Sencha之后构建了PhoneGap加载。在包构建中加载Sencha后检查DOM时,可以清楚地看到这一点

  • 我已经将我的
    app.json
    文件配置为包含PhoneGap和 我在
    app.js
    之前的插件和Sencha Touch框架。玩 按照我的
    app.json
    中JS文件引用的顺序 似乎会影响加载顺序

  • 我还尝试创建一个脚本加载程序,如前所述 (堆栈溢出)。然后我为Cordova运行脚本加载程序,并在 回调,为我的插件运行脚本加载器,然后 然后,最后,在回调中,运行senchatouch 微型装载机。这导致了一个错误。此外,我不得不 在Sencha构建我的 包裹这似乎是不可接受的

  • 我在寻找什么:我在寻找以下问题的答案:

  • 是否有办法配置Sencha的microloader或我的Sencha应用程序,以确保Cordova在Sencha的microloader运行之前已加载

  • 有没有一种方法可以设置它,以便使用Sencha Cmd仍然有效,并且在我构建应用程序之后,我不必在index.html文件中到处乱动

  • 注:
    *请不要建议我为Sencha使用现有的所谓SQLite代理。我特别选择我的方法是因为,尽管我很欣赏Sencha Touch 2的SQLite代理(即)的现有工作,但它实际上是一个WebSQL代理,不在iOS上的SQLite中本机存储。我的代理使用PhoneGap的PGSQLite插件在iOS上以本机方式将数据存储在SQLite中。我计划在有机会清理它并将其从代码中分离出来时将其开源。

    我最终通过构建自定义加载程序解决了这个问题。我不确定是否有一种更像Sencha的方法可以做到这一点,但以下是我所做的详细说明,它确实有效,以防其他人希望在Sencha中运行任何东西之前,确保PhoneGap完全加载到包和生产版本中。(在PhoneGap打包Sencha应用程序的所有场景中都可能是这样)

    My index.html文件:

    <!DOCTYPE HTML>
    <html manifest="" lang="en-US">
    <head>
        <!-- Load Cordova first. Replace with whatever version you are using -->
        <script type="text/javascript" src="cordova.js"></script>    
        <script type="text/javascript" charset="utf-8">
            function onBodyLoad() {
                // Check for whatever mobile you will run your PhoneGap app
                // on. Below is a list of iOS devices. If you have a ton of
                // devices, you can probably do this more elegantly.
                // The goal here is to only listen to the onDeviceReady event
                // to continue the load process on devices. Otherwise you will
                // be waiting forever (literally) on Desktops.
                if ((navigator.platform == 'iPad') ||
                    (navigator.platform == 'iPhone') ||
                    (navigator.platform == 'iPod') ||
                    (navigator.platform == 'iPhone Simulator') ||
                    (navigator.platform == 'iPadSimulator')
                   ) {
                  // Listening for this event to continue the load process ensures
                  // that Cordova is loaded.
                  document.addEventListener("deviceready", onDeviceReady, false);
                } else {
                    // If we're on Desktops, just proceed with loading Sencha.
                    loadScript('loader.js', function() {
                        console.log('Finished loading scripts.');
                    });
                }
            };
    
            // This function is a modified version of the one found on
            // StackOverflow, here: http://stackoverflow.com/questions/756382/bookmarklet-wait-until-javascript-is-loaded#answer-756526
            // Using this allows you to wait to load another script by
            // putting the call to load it in a callback, which is
            // executed only when the script that loadScript is loading has
            // been loaded.
            function loadScript(url, callback)
            {
                var head = document.getElementsByTagName("head")[0];
                var script = document.createElement("script");
                script.src = url;
    
                // Attach handlers for all browsers
                var done = false;
                script.onload = script.onreadystatechange = function()
                {
                    if( !done && ( !this.readyState 
                                || this.readyState == "loaded" 
                                || this.readyState == "complete") )
                    {
                        done = true;
    
                        // Continue your code
                        callback();
                    }
                };
    
                head.appendChild(script);
    
    
            }
    
            function onDeviceReady() {
                console.log("[PhoneGap] Device initialized.");
                console.log("[PhoneGap] Loading plugins.");
    
                // You can load whatever PhoneGap plugins you want by daisy-chaining
                // callbacks together like I did with pgsqlite and Sencha.
                loadScript('pgsqlite_plugin.js', function() {
                    console.log("[Sencha] Adding loader.");
    
                    // The last one to load is the custom Sencha loader.
                    loadScript('loader.js', function() {
                        console.log('Finished loading scripts.');
                    });
                });
    
            };
        </script>
    
        <meta charset="UTF-8">
        <title>Sencha App</title>   
    </head>
    <!-- Don't forget to call onBodyLoad() in onLoad -->
    <body onLoad="onBodyLoad();">
    </body>
    </html>
    
    
    函数onBodyLoad(){
    //检查您将运行PhoneGap应用程序的任何手机
    //下面是iOS设备的列表。如果您有大量的
    //设备,您可能可以更优雅地执行此操作。
    //这里的目标是只听OnDevicerady事件
    //在设备上继续加载过程。否则,您将
    //永远(字面上)在桌面上等待。
    如果((navigator.platform=='iPad')||
    (navigator.platform==“iPhone”)||
    (navigator.platform==“iPod”)||
    (navigator.platform==“iPhone模拟器”)||
    (navigator.platform==“iPadSimulator”)
    ) {
    //侦听此事件以继续加载过程可确保
    //科多娃上膛了。
    文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
    }否则{
    //如果我们在台式机上,只需继续加载Sencha即可。
    loadScript('loader.js',function(){
    log('已完成加载脚本');
    });
    }
    };
    //此函数是上的函数的修改版本
    //StackOverflow,这里:http://stackoverflow.com/questions/756382/bookmarklet-wait-until-javascript-is-loaded#answer-756526
    //使用此选项,您可以等待加载另一个脚本
    //将调用加载到回调中,这是
    //仅当loadScript正在加载的脚本
    //已加载。
    函数装入脚本(url、回调)
    {
    var head=document.getElementsByTagName(“head”)[0];
    var script=document.createElement(“脚本”);
    script.src=url;
    //为所有浏览器附加处理程序
    var done=false;
    script.onload=script.onreadystatechange=function()
    {
    如果(!done&&(!this.readyState)
    ||this.readyState==“已加载”
    ||this.readyState==“完成”))
    {
    完成=正确;
    //继续你的代码
    回调();
    }
    };
    
    console.log("Loader included.");
    
    (function() {
        function write(content) {
            document.write(content);
        }
    
        function meta(name, content) {
            write('<meta name="' + name + '" content="' + content + '">');
        }
    
        var global = this;
    
        if (typeof Ext === 'undefined') {
            var Ext = global.Ext = {};
        }
    
        var head = document.getElementsByTagName("head")[0];
    
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'app.json', false);
        xhr.send(null);
    
        var options = eval("(" + xhr.responseText + ")"),
            scripts = options.js || [],
            styleSheets = options.css || [],
            i, ln, path;
    
        meta('viewport', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no');
        meta('apple-mobile-web-app-capable', 'yes');
        meta('apple-touch-fullscreen', 'yes');
    
        console.log("Loading stylesheets");
        for (i = 0,ln = styleSheets.length; i < ln; i++) {
            path = styleSheets[i];
    
            if (typeof path != 'string') {
                path = path.path;
            }
    
            var stylesheet = document.createElement("link");
            stylesheet.rel = "stylesheet";
            stylesheet.href = path;
    
            head.appendChild(stylesheet);
        }
    
        for (i = 0,ln = scripts.length; i < ln; i++) {
            path = scripts[i];
    
            if (typeof path != 'string') {
                path = path.path;
            }
    
            var script = document.createElement("script");
            script.src = path;
            head.appendChild(script);
        }
    
    })();