13

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, your app is available nearly immediately, or within a few hours. But Apple takes ages to review your app, even when it's only a small change.

So I was thinking, if there is a way to support some kind of live update.
That means, I could provide a ZIP file or something else with a new codebase, my app checks for updates and then installs the new files.

I've read something from appmobi, but are there any open source solutions?

3
  • You should probably take a minute or two to review your iOS Developer Program License Agreement. What you're proposing isn't a new idea, but it doesn't happen because it's a violation of your agreement with Apple.
    – sherb
    Nov 22, 2014 at 1:34
  • 1
    But I know some games which regurarly fetch updates. Are they also violating the agreement?
    – 23tux
    Nov 22, 2014 at 16:39
  • Content updates are permitted, but executable code is not. There's a difference between code and content that is arguably blurry in some cases. I'm not a lawyer, but as a fellow developer my only advice is to proceed with caution. Good luck!
    – sherb
    Nov 22, 2014 at 17:53

9 Answers 9

6

cordova-app-loader is an easy to use plugin to update app files via 3 simple steps:

  1. check() for a new manifest
  2. download() files
  3. update() your app!

It supports android and iOS

1
  • 1
    Cool, this seems to be te perfect solution. I'll gibe it a try next week
    – 23tux
    Apr 26, 2015 at 15:58
4
+75

I don't know of any ready made solutions for that, but it should be easy enough to program something like this on your own. Here are some points to get you started and to consider:

  • If you want to distribute updates via zip, you need a nativ plugin which handles the extraction
  • You might not be able to override files in the default location of your app (depending on OS). So, all files you want to update in the future have to sit in a folder your app has read/write access to (iOS: e.g. Library or Documents folder)
  • Now you simply need to download the zip-package, unpack the zip to your chosen directory, and restart/reload your app.
  • you will not be able to update native plugins!
  • Apple probably doesn't like that, since you are able to change the whole application without passing their review process
2
  • Yep, that's kinda the way I also would implement it myself. Unfortunately, it seems that there are no open source solutions yet.
    – 23tux
    Nov 25, 2014 at 15:04
  • 1
    Actually Apple's all fine with it: meteor.com/blog/2014/10/02/Apple-hot-code-push-mobile As long as you don't "change the primary purpose of the Application".
    – Richard
    Nov 28, 2014 at 16:04
2

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

}
2
  • In case you update your Css how do you deal with new linked resources like images or font inside the css? Do you update the App or are you linking the resources with an absolute path to the web server? Nov 27, 2014 at 11:55
  • 1
    I use a sass to I then compile the webserver's absolute path into the css file.
    – TWilly
    Nov 30, 2014 at 15:15
2

I think the best choice would be to not try to do this with Phonegap, but rather identify your dynamic parts and implement these in Javascript.

Yes, I mean you should indeed use Javascript yourself without Phonegap, for example via JavaScriptBridge: https://github.com/kishikawakatsumi/JavaScriptBridge

It may require more work initially to redesign your app into a "static" part (your PhoneGap app) and dynamic part (dynamic created views via JavascriptBirdge), and interacte seemlessly between them. But in my opinion, that will be ultimately the best software design.

However, also make sure you still meet Apples AppStore requirements.

1

Well, Adobe offers exactly that service in their Phonegap Build service. It's called Hydration.

The example shows using it with Android and iOS platforms, so I guess they made it compatible with the iOS Dev Program License Agreement.

If you are using Cordova, you probably will have to switch to the Phonegap CLI if you want to use their build cloud services, which is basically the same as Cordova's with some extra commands to upload to their cloud, etc.

I think there are some plugin like Splashscreen wich also have some minor changes (using <gap>for params into config.xml instead of <preference>). Again, if Hydration solves the problem for you, the changes are minor and you get a really nice feature.

2
  • Cool, I didn't know that they offer such a service. But as cool as it is, I would prefer an open source solution (which isn't here, yet ;))
    – 23tux
    Nov 25, 2014 at 15:05
  • 2
    yeah... So, if you finally implement yourself a solution... make sure to open-source it ;-)
    – jrub
    Nov 25, 2014 at 17:18
1

The Meteor framework provides exactly this functionality when combined with PhoneGap. It's even sanctioned by Apple in the latest Developer Agreement. Here are some technical details and then some about Apple's view on it.

0

I think there is no such solution is available, but you can do it by programmatic way.you can update your cardova app by fetching files from server and updating it.

0

Check out CodePush from Microsoft. Works with Cordova and React Native.

Appears to be very similar to the "live update" feature from Ionic Cloud.

1
  • Unfortunately, Microsoft has dropped Cordova support and this is not an option anymore. I was a good alternative though.
    – Uzbekjon
    Apr 6, 2023 at 4:48
0

If you migrate to capacitor, the successor of Cordova there open source solution now.

Capacitor-updater, is the only alternative to ionic AppFlow.

The updater allows you to manage update by yourself, store your zip update where you want and use the download method.

How to start

npm install @capgo/capacitor-updater
npx cap sync

Then in your main JS, this is required to let the updater know the update is valid

  import { CapacitorUpdater } from '@capgo/capacitor-updater'
  CapacitorUpdater.notifyAppReady()
And lately after checking yourself the current version need update:

  const version = await CapacitorUpdater.download({
    url: 'https://github.com/Cap-go/demo-app/releases/download/0.0.4/dist.zip',
  })
  await CapacitorUpdater.set(version); // sets the new version, and reloads the app

After many request of people didn't want to do that themselves, I started Capgo a business to manage all the update process.

All is open source and can be replicate on your own as well.

Doing things for Capacitor is now my main activity, I produce open-source plugin as my main channel of Marketing, I'm solo founder and bootstrapped.

Hope my tool will help you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.