Cordova / Phonegap: Live update codebase

后端 未结 8 2078
半阙折子戏
半阙折子戏 2021-02-07 19:17

We are using Cordova along with AngularJS for iOS and Android applications.

One big disadvantage of iOS are the long review times from Apple. In Google\'s Playstore, yo

8条回答
  •  礼貌的吻别
    2021-02-07 19:42

    I'm doing this inside my cordova app and haven't had any issues with ios app store review.

    I'm using Jquery's ajax function to download both a javascript and a css file from a server that I can change without an app store approval and then I can inject those scripts once they downloaded on app startup.

    I tried using the cordova File api and I'd then save the file locally, but offline support ins't the important to me at the moment and Jquery's ajax is much simpler.

    Here is the jquery code I use. I have a bundle id that I use to detect if a new javascript file is available, otherwise jquery's ajax caches the previous requests to speed up download time.

    This solution lets you have a subset of your code be dynamic. I still have a base set of code that is bundled with the app, along with native plugin js and native code which would need to go through the app store. But this atleast lets me push bug fixes without going through the app store.

    Otherwise, I'd look at a solution like this: http://docs.build.phonegap.com/en_US/tools_hydration.md.html

    function insertScript(version) {
        var scriptUrl = "";
        try {
            // get javascript file...
            scriptUrl = mobileWebServiceUrl + "/DynamicContent/Bundles/Scripts/dynamic";
    
            scriptUrl += "_" + bundleVersion.replace(/\./g, "_") + ".js?v=" + version;
    
            console.log("downloading script: " + scriptUrl);
    
            // Allow user to set any option except for dataType, cache, and url
            options = {
                dataType: "script",
                cache: true,
                url: scriptUrl
            };
    
            // Use $.ajax() since it is more flexible than $.getScript
            // Return the jqXHR object so we can chain callbacks
            return $.ajax(options).success(function(response) {
                console.log("insertScript success");
                dynamicContentScriptLoaded = true;
            });
    
    
        } catch (e) {
            //console.error(e);
            ReportError("problem downloading javscript: " + scriptUrl);
        }
    
    }
    
    
    function insertCSS(version) {
        try {
            // get css file...
            var cssUrl = mobileWebServiceUrl + "/DynamicContent/Bundles/Css/dynamic";
    
            cssUrl += "_" + bundleVersion.replace(/\./g, "_") + ".css?v=" + version;
    
            console.log("downloading dynamic css: " + cssUrl);
    
            $.ajax(cssUrl)
                .success(function (response) {
                    console.log("successfully downloaded dynamic css");
                    var script = document.createElement("style");
                    script.type = "text/css";
                    script.innerHTML = response;
    
                    $('head link').each(function () {
                        if ($(this).attr('href').search('MobileFrame') > -1) {
                            $("#MobileFrameCSS").before(script);
                        }
                    });
    
                    dynamicContentCssLoaded = true;
    
                    // TODO: implement caching at a later date
                    //if (isPhoneGap())
                    //    saveFile("DynamicStyles", response);
    
                });
        } catch (e) {
            ReportError("problem downloading css");
        }
    
    }
    

提交回复
热议问题