Giter Site home page Giter Site logo

microsoft / cordova-plugin-code-push Goto Github PK

View Code? Open in Web Editor NEW
645.0 83.0 324.0 1.57 MB

Cordova plugin for CodePush

Home Page: http://appcenter.ms

License: Other

JavaScript 19.11% HTML 0.12% Java 9.59% Objective-C 39.39% TypeScript 31.66% C 0.14%
codepush cordova

cordova-plugin-code-push's Introduction

Cordova support is retired in App Center

Check our blog post for more information.

Apache Cordova Plugin for CodePush

This plugin provides client-side integration for the CodePush service, allowing you to easily add a dynamic update experience to your Cordova app(s).

How does it work?

A Cordova app is composed of HTML, CSS and JavaScript files and any accompanying images, which are bundled together by the Cordova CLI and distributed as part of a platform-specific binary (i.e. an .ipa or .apk file). Once the app is released, updating either the code (e.g. making bug fixes, adding new features) or image assets, requires you to recompile and redistribute the entire binary, which of course, includes any review time associated with the store(s) you are publishing to.

The CodePush plugin helps get product improvements in front of your end users instantly, by keeping your code and images synchronized with updates you release to the CodePush server. This way, your app gets the benefits of an offline mobile experience, as well as the "web-like" agility of side-loading updates as soon as they are available. It's a win-win!

In order to ensure that your end users always have a functioning version of your app, the CodePush plugin maintains a copy of the previous update, so that in the event that you accidentally push an update which includes a crash, it can automatically roll back. This way, you can rest assured that your newfound release agility won't result in users becoming blocked before you have a chance to roll back on the server. It's a win-win-win!

Note: Any product changes which touch native code (e.g. upgrading Cordova versions, adding a new plugin) cannot be distributed via CodePush, and therefore, must be updated via the appropriate store(s).

Supported Cordova Platforms

Cordova 5.0.0+ is fully supported, along with the following associated platforms:

  • Android (cordova-android 4.0.0+) - Including CrossWalk! Note: Only on TLS 1.2 compatible devices
  • iOS (cordova-ios 3.9.0+) - please see notes below.

Note: Starting with v2.0.0 cordova-plugin-code-push doesn't support apps using UIWebView due to Apple officially deprecated it and discourage developers from using it. Prior versions of the plugin still support UIWebView but be aware that the App Store will no longer accept new apps using UIWebView as of April 2020 and app updates using UIWebView as of December 2020.

Note: In order to use CodePush along with the cordova-plugin-wkwebview-engine plugin, you need to install v1.5.1-beta+ version of cordova-plugin-code-push, which includes full support for apps using either WebView. Please see Using WKWebView section for more information of how to confiure your app to use cordova-plugin-wkwebview-engine.

To check which versions of each Cordova platform you are currently using, you can run the following command and inspect the Installed platforms list:

cordova platform ls

If you're running an older Android and/or iOS platform than is mentioned above, and would be open to upgrading, you can easily do so by running the following commands (omitting a platform if it isn't necessary):

cordova platform update android
cordova platform update ios

Deprecating old versions

Since CodePush is migrating to a new service all versions of cordova-plugin-code-push lower than 1.12.0 will not work in the nearest future.

You can find more information in our documentation.

Getting Started

Once you've followed the general-purpose "getting started" instructions for setting up your CodePush account, you can start CodePush-ifying your Cordova app by running the following command from within your app's root directory:

cordova plugin add cordova-plugin-code-push@latest

With the CodePush plugin installed, configure your app to use it via the following steps:

  1. Add your deployment keys to the config.xml file, making sure to include the right key for each Cordova platform:

    <platform name="android">
        <preference name="CodePushDeploymentKey" value="YOUR-ANDROID-DEPLOYMENT-KEY" />
    </platform>
    <platform name="ios">
        <preference name="CodePushDeploymentKey" value="YOUR-IOS-DEPLOYMENT-KEY" />
    </platform>

    As a reminder, these keys are generated for you when you created your CodePush app via the CLI. If you need to retrieve them, you can simply run appcenter codepush deployment list <ownerName>/<appName> --displayKeys, and grab the key for the specific deployment you want to use (e.g. Staging, Production).

    NOTE: You must create a separate CodePush app for iOS and Android, which is why the above sample illustrates declaring separate keys for Android and iOS. If you're only developing for a single platform, then you only need to specify the deployment key for either Android or iOS, so you don't need to add the additional <platform> element as illustrated above.

    Beginning from version 1.10.0 you can sign your update bundles (for more information about code signing please refer to relevant documentation section). In order to enable code signing for Cordova application you should setup public key to verify bundles signature by providing following preference setting in config.xml:

    <platform name="android">
       ...
       <preference name="CodePushPublicKey" value="YOUR-PUBLIC-KEY" />
    </platform>
    <platform name="ios">
       ...
       <preference name="CodePushPublicKey" value="YOUR-PUBLIC-KEY" />
    </platform>

    You can use the same private/public key pair for each platform.

  2. If you're using an <access origin="*" /> element in your config.xml file, then your app is already allowed to communicate with the CodePush servers and you can safely skip this step. Otherwise, add the following additional <access /> elements:

    <access origin="https://codepush.appcenter.ms" />
    <access origin="https://codepush.blob.core.windows.net" />
    <access origin="https://codepushupdates.azureedge.net" />
  3. To ensure that your app can access the CodePush server on CSP-compliant platforms, add https://codepush.appcenter.ms to the Content-Security-Policy meta tag in your index.html file:

    <meta http-equiv="Content-Security-Policy" content="default-src https://codepush.appcenter.ms 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />
  4. Finally, double-check that you already have the cordova-plugin-whitelist plugin installed (most apps will). To check this, simply run the following command:

    cordova plugin ls

    If cordova-plugin-whitelist is in the list, then you are good to go. Otherwise, simply run the following command to add it:

    cordova plugin add cordova-plugin-whitelist

You are now ready to use the plugin in the application code. See the sample applications for examples and the API documentation for more details.

Using WKWebView

For cordova-ios v4-v5 there is a possibility to specify WebView engine on the plugin build phase. By default UIWebView engine is used. To use WKWebView engine please do the following:

Note: cordova-plugin-wkwebview-engine is just a workaround for cordova-ios v4-v5 users to be able to use WKWebView in their apps to avoid stop accepting updates via AppStore as of December 2020. Cordova-ios v6+ has full support for native WKWebView and doesn't require cordova-plugin-wkwebview-engine.

Plugin Usage

With the CodePush plugin installed and configured, the only thing left is to add the necessary code to your app to control the following policies:

  1. When (and how often) to check for an update? (e.g. app start, in response to clicking a button in a settings page, periodically at some fixed interval)

  2. When an update is available, how to present it to the end user?

The simplest way to do this is to perform the following in your app's deviceready event handler:

codePush.sync();

If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If an available update is mandatory, then it will be installed immediately, ensuring that the end user gets it as soon as possible.

If you would like your app to discover updates more quickly, you can also choose to call sync every time the app resumes from the background, by adding the following code (or something equivalent) as part of your app's startup behavior. You can call sync as frequently as you would like, so when and where you call it just depends on your personal preference.

document.addEventListener("resume", function () {
    codePush.sync();
});

Additionally, if you would like to display an update confirmation dialog (an "active install"), configure when an available update is installed (e.g. force an immediate restart) or customize the update experience in any way, refer to the sync method's API reference for information on how to tweak this default behavior.

NOTE: While Apple's developer agreement fully allows performing over-the-air updates of JavaScript and assets (which is what enables CodePush!), it is against their policy for an app to display an update prompt. Because of this, we recommend that App Store-distributed apps don't enable the updateDialog option when calling sync, whereas Google Play and internally distributed apps (e.g. Enterprise, Fabric, HockeyApp) can choose to enable/customize it.

Releasing Updates

Once your app has been configured and distributed to your users, and you've made some code and/or asset changes, it's time to instantly release them! The simplest (and recommended) way to do this is to use the release-cordova command in the App Center CLI, which will handle preparing and releasing your update to the CodePush server.

NOTE: Before you can start releasing updates, please log into App Center by running the appcenter login command

In it's the most basic form, this command only requires one parameter: your owner name + "/" + app name.

appcenter codepush release-cordova -a <ownerName>/<appName>

appcenter codepush release-cordova -a <ownerName>/MyApp-ios
appcenter codepush release-cordova -a <ownerName>/MyApp-Android

NOTE: When releasing updates to CodePush, you do not need to bump your app's version in the config.xml file, since you aren't modifying the binary version at all. You only need to bump this version when you upgrade Cordova and/or one of your plugins, at which point, you need to release an update to the native store(s). CodePush will automatically generate a "label" for each release you make (e.g. v3) in order to help identify it within your release history.

The release-cordova command enables such a simple workflow because it understands the standard layout of a Cordova app, and therefore, can generate your update and know exactly which files to upload. Additionally, in order to support flexible release strategies, the release-cordova command exposes numerous optional parameters that let you customize how the update should be distributed to your end users (e.g. Which binary versions are compatible with it? Should the release be viewed as mandatory?).

# Release a mandatory update with a changelog
appcenter codepush release-cordova -a <ownerName>/MyApp-ios -m --description "Modified the header color"

# Release a dev Android build to just 1/4 of your end users
appcenter codepush release-cordova -a <ownerName>/MyApp-android --rollout 25

# Release an update that targets users running any 1.1.* binary, as opposed to
# limiting the update to exact version name in the config.xml file
appcenter codepush release-cordova -a <ownerName>/MyApp-android --target-binary-version "~1.1.0"

# Release an update now but mark it as disabled
# so that no users can download it yet
appcenter codepush release-cordova -a <ownerName>/MyApp-ios -x

# Release an update signed by private key (public key should be configured for application)
appcenter codepush release-cordova -a <ownerName>/MyApp-android --private-key-path ~/rsa/private_key.pem

The CodePush client supports differential updates, so even though you are releasing your app code on every update, your end users will only actually download the files they need. The service handles this automatically so that you can focus on creating awesome apps and we can worry about optimizing end user downloads.

NOTE: for Ionic apps you need to run ionic build before running cordova-release or release command in order to build web assets.

For more details about how the release-cordova command works, as well as the various parameters it exposes, refer to the CLI docs. Additionally, if you would prefer to handle running the cordova prepare command yourself, and therefore, want an even more flexible solution than release-cordova, refer to the release command for more details.

If you run into any issues, or have any questions/comments/feedback, you can e-mail us and/or open a new issue on this repo and we'll respond ASAP!

API Reference

The CodePush API is exposed to your app via the global codePush object, which is available after the deviceready event fires. This API exposes the following top-level methods:

  • checkForUpdate: Asks the CodePush service whether the configured app deployment has an update available.

  • getCurrentPackage: Retrieves the metadata about the currently installed update (e.g. description, installation time, size).

  • getPendingPackage: Retrieves the metadata for an update (if one exists) that was downloaded and installed, but hasn't been applied yet via a restart.

  • notifyApplicationReady: Notifies the CodePush runtime that an installed update is considered successful. If you are manually checking for and installing updates (i.e. not using the sync method to handle it all for you), then this method MUST be called; otherwise CodePush will treat the update as failed and rollback to the previous version when the app next restarts.

  • restartApplication: Immediately restarts the app. If there is an update pending, it will be immediately displayed to the end user.

  • sync: Allows checking for an update, downloading it and installing it, all with a single call. Unless you need custom UI and/or behavior, we recommend most developers to use this method when integrating CodePush into their apps.

Additionally, the following objects and enums are also exposed globally as part of the CodePush API:

  • InstallMode: Defines the available install modes for updates.

  • LocalPackage: Contains information about a locally installed package.

  • RemotePackage: Contains information about an update package available for download.

  • SyncStatus: Defines the possible intermediate and result statuses of the sync operation.

codePush.checkForUpdate

codePush.checkForUpdate(onSuccess, onError?, deploymentKey?: String);

Queries the CodePush service to see whether the configured app deployment has an update available. By default, it will use the deployment key that is configured in your config.xml file, but you can override that by specifying a value via the optional deploymentKey parameter. This can be useful when you want to dynamically "redirect" a user to a specific deployment, such as allowing "Early access" via an easter egg or a user setting switch.

When the update check completes, it will trigger the onUpdateCheck callback with one of two possible values:

  1. null if there is no update available. This occurs in the following scenarios:

    1. The configured deployment doesn't contain any releases, and therefore, nothing to update.

    2. The latest release within the configured deployment is targeting a different binary version than what you're currently running (either older or newer).

    3. The currently running app already has the latest release from the configured deployment, and therefore, doesn't need it again.

  2. A RemotePackage instance which represents an available update that can be inspected and/or subsequently downloaded.

Parameters:

  • onSuccess: Callback that is invoked upon receiving a successful response from the server. The callback receives a single parameter, which is described above.

  • onError: Optional callback that is invoked in the event of an error. The callback takes one error parameter, containing the details of the error.

  • deploymentKey: Optional deployment key that overrides the config.xml setting.

Example usage:

codePush.checkForUpdate(function (update) {
    if (!update) {
        console.log("The app is up to date.");
    } else {
        console.log("An update is available! Should we download it?");
    }
});

codePush.getCurrentPackage

codePush.getCurrentPackage(onSuccess, onError?);

Retrieves the metadata about the currently installed "package" (e.g. description, installation time). This can be useful for scenarios such as displaying a "what's new?" dialog after an update has been applied or checking whether there is a pending update that is waiting to be applied via a resume or restart.

When the update retrieval completes, it will trigger the onSuccess callback with one of two possible values:

  1. null if the app is currently running the HTML start page from the binary and not a CodePush update. This occurs in the following scenarios:

    1. The end-user installed the app binary and has yet to install a CodePush update

    2. The end-user installed an update of the binary (e.g. from the store), which cleared away the old CodePush updates, and gave precedence back to the binary.

  2. A LocalPackage instance which represents the metadata for the currently running CodePush update.

Parameters:

  • onSuccess: Callback that is invoked upon receiving the metadata about the currently running update. The callback receives a single parameter, which is described above.

  • onError: Optional callback that is invoked in the event of an error. The callback takes one error parameter, containing the details of the error.

Example Usage:

codePush.getCurrentPackage(function (update) {
    if (!update) {
        console.log("No updates have been installed");
        return;
    }

    // If the current app "session" represents the first time
    // this update has run, and it had a description provided
    // with it upon release, let's show it to the end user
    if (update.isFirstRun && update.description) {
        // Display a "what's new?" modal
    }
});

codePush.getPendingPackage

codePush.getPendingPackage(onSuccess, onError?);

Gets the metadata for the currently pending update (if one exists). An update is considered "pending" if it has been downloaded and installed, but hasn't been applied yet via an app restart. An update could only ever be in this state if InstallMode.ON_NEXT_RESTART or InstallMode.ON_NEXT_RESUME were specified upon calling sync or LocalPackage.install, and the app hasn't yet been restarted or resumed (respectively). This method can be useful if you'd like to determine whether there is a pending update and then prompt the user if they would like to restart now (via codePush.restartApplication) in order to apply it.

When the update retrieval completes, it will trigger the onSuccess callback with one of two possible values:

  1. null if the app doesn't currently have a pending update (e.g. the app is already running the latest available version).

  2. A LocalPackage instance which represents the metadata for the currently pending CodePush update.

Parameters:

  • onSuccess: Callback that is invoked upon receiving the metadata about the currently pending update. The callback receives a single parameter, which is described above.

  • onError: Optional callback that is invoked in the event of an error. The callback takes one error parameter, containing the details of the error.

Example Usage:

codePush.getPendingPackage(function (update) {
    if (update) {
        // An update is currently pending, ask the
        // user if they would like to restart
    }
});

codePush.notifyApplicationReady

codePush.notifyApplicationReady(notifySucceeded?, notifyFailed?);

Notifies the CodePush runtime that a freshly installed update should be considered successful, and therefore, an automatic client-side rollback isn't necessary. It is mandatory to call this function somewhere in the code of the updated bundle. Otherwise, when the app next restarts, the CodePush runtime will assume that the installed update has failed and roll back to the previous version. This behavior exists to help ensure that your end users aren't blocked by a broken update.

If you are using the sync function, and doing your update check on app start, then you don't need to manually call notifyApplicationReady since sync will call it for you. This behavior exists due to the assumption that the point at which sync is called in your app represents a good approximation of a successful startup.

Parameters:

  • notifySucceeded: Optional callback invoked if the plugin was successfully notified.

  • notifyFailed: Optional callback invoked in case of an error during notifying the plugin.

codePush.restartApplication

codePush.restartApplication();

Immediately restarts the app. This method is for advanced scenarios, and is primarily useful when the following conditions are true:

  1. Your app is specifying an install mode value of ON_NEXT_RESTART or ON_NEXT_RESUME when calling the sync or LocalPackage.install methods. This has the effect of not applying your update until the app has been restarted (by either the end user or OS) or resumed, and therefore, the update won't be immediately displayed to the end user.

  2. You have an app-specific user event (e.g. the end user navigated back to the app's home route) that allows you to apply the update in an unobtrusive way, and potentially gets the update in front of the end user sooner then waiting until the next restart or resume.

codePush.sync

codePush.sync(syncCallback?, syncOptions?, downloadProgress?, syncErrback?);

Synchronizes your app's code and images with the latest release to the configured deployment. Unlike the checkForUpdate method, which simply checks for the presence of an update, and let's you control what to do next, sync handles the update check, download and installation experience for you.

This method provides support for two different (but customizable) "modes" to easily enable apps with different requirements:

  1. Silent mode (the default behavior), which automatically downloads available updates, and applies them the next time the app restarts (e.g. the OS or end user killed it, or the device was restarted). This way, the entire update experience is "silent" to the end user, since they don't see any update prompt and/or "synthetic" app restarts.

  2. Active mode, which when an update is available, prompts the end user for permission before downloading it, and then immediately applies the update. If an update was released using the mandatory flag, the end user would still be notified about the update, but they wouldn't have the choice to ignore it.

Example Usage:

// Fully silent update which keeps the app in
// sync with the server, without ever
// interrupting the end user
codePush.sync();

// Active update, which lets the end user know
// about each update, and displays it to them
// immediately after downloading it
codePush.sync(null, { updateDialog: true, installMode: InstallMode.IMMEDIATE });

Note: If you want to decide whether you check and/or download an available update based on the end user's device battery level, network conditions, etc. then simply wrap the call to sync in a condition that ensures you only call it when desired.

While the sync method tries to make it easy to perform silent and active updates with little configuration, it accepts the following optional parameters which allow you to customize numerous aspects of the default behavior mentioned above:

  • syncCallback: Called when the sync process moves from one stage to another in the overall update process. The method is called with a status code which represents the current state, and can be any of the SyncStatus values.

  • syncOptions: Optional SyncOptions parameter configuring the behavior of the sync operation.

  • downloadProgress: Called periodically when an available update is being downloaded from the CodePush server. The method is called with a DownloadProgress object, which contains the following two properties:

    • totalBytes (Number) - The total number of bytes expected to be received for this update (i.e. the size of the set of files which changed from the previous release).

    • receivedBytes (Number) - The number of bytes downloaded thus far, which can be used to track download progress.

SyncOptions

While the sync method tries to make it easy to perform silent and active updates with little configuration, it accepts an "options" object that allows you to customize numerous aspects of the default behavior mentioned above:

  • deploymentKey (String) - Specifies the deployment key you want to query for an update against. By default, this value is derived from the config.xml file, but this option allows you to override it from the script-side if you need to dynamically use a different deployment for a specific call to sync.

  • installMode (InstallMode) - Specifies when you would like to install optional updates (i.e. those that aren't marked as mandatory). Defaults to InstallMode.ON_NEXT_RESTART. Refer to the InstallMode enum reference for a description of the available options and what they do.

  • mandatoryInstallMode (InstallMode) - Specifies when you would like to install updates which are marked as mandatory. Defaults to InstallMode.IMMEDIATE. Refer to the InstallMode enum reference for a description of the available options and what they do.

  • minimumBackgroundDuration (Number) - Specifies the minimum number of seconds that the app needs to have been in the background before restarting the app. This property only applies to updates which are installed using InstallMode.ON_NEXT_RESUME, and can be useful for getting your update in front of end users sooner, without being too obtrusive. Defaults to 0, which has the effect of applying the update immediately after a resume, regardless how long it was in the background.

  • ignoreFailedUpdates (Boolean) - Specifies whether an available update should be ignored if it had been previously installed and rolled back on the client (because notifyApplicationReady wasn't successfully called). Defaults to true.

  • updateDialog (UpdateDialogOptions) - An "options" object used to determine whether a confirmation dialog should be displayed to the end user when an update is available, and if so, what strings to use. Defaults to null, which has the effect of disabling the dialog completely. Setting this to any truthy value will enable the dialog with the default strings, and passing an object to this parameter allows enabling the dialog as well as overriding one or more of the default strings.

    The following list represents the available options and their defaults:

    • appendReleaseDescription (Boolean) - Indicates whether you would like to append the description of an available release to the notification message which is displayed to the end user. Defaults to false.

    • descriptionPrefix (String) - Indicates the string you would like to prefix the release description with, if any, when displaying the update notification to the end user. Defaults to " Description: ".

    • mandatoryContinueButtonLabel (String): The text to use for the button the end user must press in order to install a mandatory update. Defaults to "Continue".

    • mandatoryUpdateMessage (String) - The text used as the body of an update notification, when the update is specified as mandatory. Defaults to "An update is available that must be installed.".

    • optionalIgnoreButtonLabel (String) - The text to use for the button the end user can press in order to ignore an optional update that is available. Defaults to "Ignore".

    • optionalInstallButtonLabel (String) - The text to use for the button the end user can press in order to install an optional update. Defaults to "Install".

    • optionalUpdateMessage (String) - The text used as the body of an update notification, when the update is optional. Defaults to "An update is available. Would you like to install it?".

    • updateTitle (String) - The text used as the header of an update notification that is displayed to the end user. Defaults to "Update available".

Example Usage:

// Download the update silently, but install it on
// the next resume, as long as at least 5 minutes
// has passed since the app was put into the background.
codePush.sync(null, { installMode: InstallMode.ON_NEXT_RESUME, minimumBackgroundDuration: 60 * 5 });

// Download the update silently, and install optional updates
// on the next restart, but install mandatory updates on the next resume.
codePush.sync(null, { mandatoryInstallMode: InstallMode.ON_NEXT_RESUME });

// Changing the title displayed in the
// confirmation dialog of an "active" update
codePush.sync(null, { updateDialog: { updateTitle: "An update is available!" } });

// Displaying an update prompt which includes the
// description associated with the CodePush release
codePush.sync(null, {
   updateDialog: {
    appendReleaseDescription: true,
    descriptionPrefix: "\n\nChange log:\n"
   },
   installMode: InstallMode.IMMEDIATE
});

// Silently check for the update, but
// display a custom downloading UI
// via the SyncStatus and DownloadProgress callbacks
codePush.sync(syncStatus, null, downloadProgress);

function syncStatus(status) {
    switch (status) {
        case SyncStatus.DOWNLOADING_PACKAGE:
            // Show "downloading" modal
            break;
        case SyncStatus.INSTALLING_UPDATE:
            // Hide "downloading" modal
            break;
    }
}

function downloadProgress(downloadProgress) {
    if (downloadProgress) {
    	// Update "downloading" modal with current download %
        //console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes);
    }
}

The sync method can be called anywhere you'd like to check for an update. That could be in the deviceready event handler, the click event of a button, in the callback of a periodic timer, or whatever else makes sense for your needs. Just like the checkForUpdate method, it will perform the network request to check for an update in the background, so it won't impact your UI thread and/or JavaScript thread's responsiveness.

Package objects

The checkForUpdate and getCurrentPackage methods invoke success callbacks, that when triggered, provide access to "package" objects. The package represents your code update as well as any extra metadata (e.g. description, mandatory?). The CodePush API has the distinction between the following types of packages:

  1. LocalPackage: Represents a downloaded update that is either already running, or has been installed and is pending an app restart.

  2. RemotePackage: Represents an available update on the CodePush server that hasn't been downloaded yet.

LocalPackage

Contains details about an update that has been downloaded locally or already installed. You can get a reference to an instance of this object either by calling the codePush.getCurrentPackage method, or as the value provided to the success callback of the RemotePackage.download method.

Properties
  • appVersion: The native version of the application this package update is intended for. (String)
  • deploymentKey: Deployment key of the package. (String)
  • description: The description of the update. This is the same value that you specified in the CLI when you released the update. (String)
  • failedInstall: Indicates whether this update has been previously installed but was rolled back. The sync method will automatically ignore updates which have previously failed, so you only need to worry about this property if using checkForUpdate. (Boolean)
  • isFirstRun: Flag indicating if the current application run is the first one after the package was applied. (Boolean)
  • isMandatory: Indicates whether the update is considered mandatory. This is the value that was specified in the CLI when the update was released. (Boolean)
  • label: The internal label automatically given to the update by the CodePush server, such as v5. This value uniquely identifies the update within it's deployment. (String)
  • packageHash: The SHA hash value of the update. (String)
  • packageSize: The size of the code contained within the update, in bytes. (Number)
Methods
  • install(installSuccess, installError, installOptions): Installs this package to the application. The install behavior is dependent on the provided installOptions. By default, the update package is silently installed and the application is reloaded with the new content on the next application start. On the first run after the update, the application will wait for a codePush.notifyApplicationReady() call. Once this call is made, the install operation is considered a success. Otherwise, the install operation will be marked as failed, and the application is reverted to its previous version on the next run.

    InstallOptions

    Interface defining several options for customizing install operation behavior.

    • installMode: Used to specify the InstallMode used for the install operation. Defaults to InstallMode.ON_NEXT_RESTART.

    • mandatoryInstallMode: Used to specify the InstallMode used for the install operation if the package is mandatory. Defaults to InstallMode.IMMEDIATE.

    • minimumBackgroundDuration: If installMode is InstallMode.ON_NEXT_RESUME, used to specify the amount of time the app must be in the background before the update is installed when it is resumed. Defaults to 0.

Example Usage:

// App version 1 (current version)

var onError = function (error) {
    console.log("An error occurred. " + error);
};

var onInstallSuccess = function () {
    console.log("Installation succeeded.");
};

var onPackageDownloaded = function (localPackage) {
    // Install regular updates after someone navigates away from the app for more than 2 minutes
    // Install mandatory updates after someone restarts the app
    localPackage.install(onInstallSuccess, onError, { installMode: InstallMode.ON_NEXT_RESUME, minimumBackgroundDuration: 120, mandatoryInstallMode: InstallMode.ON_NEXT_RESTART });
};

var onUpdateCheck = function (remotePackage) {
    if (!remotePackage) {
        console.log("The application is up to date.");
    } else {
        // The hash of each previously reverted package is stored for later use.
        // This way, we avoid going into an infinite bad update/revert loop.
        if (!remotePackage.failedInstall) {
            console.log("A CodePush update is available. Package hash: " + remotePackage.packageHash);
            remotePackage.download(onPackageDownloaded, onError);
        } else {
            console.log("The available update was attempted before and failed.");
        }
    }
};

window.codePush.checkForUpdate(onUpdateCheck, onError);

//------------------------------------------------

// App version 2 (updated version)

var app = {
    onDeviceReady: function () {
        // Calling this function is required during the first application run after an update.
        // If not called, the application will be reverted to the previous version.
        window.codePush.notifyApplicationReady();
        // ...
    }
}

For an example on how you are protected against a bad update, see the notifyApplicationReady() documentation.

RemotePackage

Contains details about an update that is available for download from the CodePush server. You get a reference to an instance of this object by calling the codePush.checkForUpdate method when an update is available. If you are using the sync API, you don't need to worry about the RemotePackage, since it will handle the download and installation process automatically for you.

Properties

The RemotePackage inherits all of the same properties as the LocalPackage, but includes one additional one:

  • downloadUrl: The URL at which the package is available for download. This property is only needed for advanced usage, since the download method will automatically handle the acquisition of updates for you. (String)
Methods
  • abortDownload(abortSuccess, abortError): Aborts the current download session, if any.

  • download(downloadSuccess, downloadError, downloadProgress): Downloads the package update from the CodePush service. The downloadSuccess callback is invoked with a LocalPackage argument, representing the downloaded package. The optional downloadProgress callback is invoked several times during the download progress with one DownloadProgress parameter.

    DownloadProgress

    Defines the format of the DownloadProgress object, used to send periodical update notifications on the progress of the update download.

    Properties

    • totalBytes: The size of the downloading update package, in bytes. (Number)
    • receivedBytes: The number of bytes already downloaded. (Number)

Example Usage:

var onError = function (error) {
    console.log("An error occurred. " + error);
};

var onPackageDownloaded = function (localPackage) {
    console.log("Package downloaded at: " + localPackage.localPath);
    // you can now update your application to the downloaded version by calling localPackage.install()
};

var onProgress = function (downloadProgress) {
    console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes + " bytes.");
};

var onUpdateCheck = function (remotePackage) {
    if (!remotePackage) {
        console.log("The application is up to date.");
    } else {
        console.log("A CodePush update is available. Package hash: " + remotePackage.packageHash);
        remotePackage.download(onPackageDownloaded, onError, onProgress);
    }
};

window.codePush.checkForUpdate(onUpdateCheck, onError);

Enums

The CodePush API includes the following "enum" objects which can be used to customize the update experience, and are available globally off of the window object:

InstallMode

This enum specified when you would like an installed update to actually be applied, and can be passed to either the sync or LocalPackage.install methods. It includes the following values:

  • IMMEDIATE: The update will be applied to the running application immediately. The application will be reloaded with the new content immediately.

  • ON_NEXT_RESTART: Indicates that you want to install the update, but not forcibly restart the app. When the app is "naturally" restarted (due the OS or end user killing it), the update will be seamlessly picked up. This value is appropriate when performing silent updates, since it would likely be disruptive to the end user if the app suddenly restarted out of nowhere, since they wouldn't have realized an update was even downloaded. This is the default mode used for both the sync and LocalPackage.install methods.

  • ON_NEXT_RESUME: Indicates that you want to install the update, but don't want to restart the app until the next time the end user resumes it from the background. This way, you don't disrupt their current session, but you can get the update in front of them sooner then having to wait for the next natural restart. This value is appropriate for silent installs that can be applied on resume in a non-invasive way.

SyncStatus

Defines the possible statuses of the sync operation. There are two categories of statuses: intermediate and result (final). The intermediate statuses represent progress statuses of the sync operation, and are not final. The result statuses represent final statuses of the sync operation. Every sync operation ends with only one result status, but can have zero or more intermediate statuses.

  • UP_TO_DATE: The app is fully up-to-date with the configured deployment.

  • UPDATE_INSTALLED: An available update has been installed and will be run either immediately after the callback function returns or the next time the app resumes/restarts, depending on the InstallMode specified in SyncOptions.

  • UPDATE_IGNORED: The app has an optional update, which the end user chose to ignore. (This is only applicable when the updateDialog is used)

  • ERROR: An error occurred during the sync operation. This might be an error while communicating with the server, downloading or unzipping the update. The console logs should contain more information about what happened. No update has been applied in this case.

  • IN_PROGRESS: Another sync is already running, so this attempt to sync has been aborted.

  • CHECKING_FOR_UPDATE: The CodePush server is being queried for an update.

  • AWAITING_USER_ACTION: An update is available, and a confirmation dialog was shown to the end user. (This is only applicable when the updateDialog is used)

  • DOWNLOADING_PACKAGE: An available update is being downloaded from the CodePush server.

  • INSTALLING_UPDATE: An available update was downloaded and is about to be installed.

PhoneGap Build

This plugin is compatible with PhoneGap Build, and supports creating Android and iOS builds out-of-the-box. However, in order for CodePush to calculate the hash of your binary contents on Android, PhoneGap Build needs to use Gradle to build your app, which isn't its default behavior (it uses Ant). To resolve this, simply add the following element to your app's config.xml file, as a child of the <platform name="android"> element:

<preference name="android-build-tool" value="gradle" />

Example Apps

The Cordova community has graciously created some awesome open source apps that can serve as examples for developers that are getting started. The following is a list of OSS Cordova apps that are also using CodePush, and can therefore be used to see how others are using the service:

Note: If you've developed a Cordova app using CodePush, that is also open-source, please let us know. We would love to add it to this list!

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

cordova-plugin-code-push's People

Contributors

alexandergoncharov-zz avatar alissonlinneker avatar botatoes avatar buptkang avatar cjonsmith avatar dasmajo avatar dlebu avatar export-mike avatar geof90 avatar itoys avatar kamengoranchev avatar lostintangent avatar lucen-ms avatar matrosov-nikita avatar matt-auckland avatar matthiaswenz avatar msftgits avatar nicktoropov avatar nitrique avatar pfleidi avatar phyr0s avatar rub8n avatar ruslan-bikkinin avatar ryuyu avatar sergey-akhalkov avatar shishirx34 avatar simon-wicki avatar svekl avatar yuri-kulikov avatar zakeelm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-code-push's Issues

Partial Updates

Is there a way to only release partial updates from the www folder?

e.g. there was only a small hotfix change in app.routes.js, i don't want to upload the whole www folder.

cordova.js not found

Hi I'm finding that after running:
code-push release app-android build/www/ 0.11.1 --deploymentName Staging

I get the following error:
file:///data/data/bundle.app.name.id/files/codepush/deploy/versions/8sds645e6325b1bfcac0181c396d377a21946f764526cd7cd0480c6c2a47d9a/www/cordova.js Failed to load resource: net::ERR_FILE_NOT_FOUND

cordova.js seems to be requested from the codepush path, how do I fix this? do I need to set cordova.js path to ../../../../../www/cordova.js ?

[Android] Update prompt should be modal/non-dismissable by touch

I'm not an Android user so I can't say whether this behavior is idiomatic or not across apps. But, it's a little odd that the update prompt isn't actually modal, and can be dismissed by touching anywhere outside of the prompt, as opposed to requiring the end-user to actually touch the accept or ignore buttons. I could kind of see this behavior making sense in the optional-update scenario, where dismissing the dialog is effectively an alternative way of ignoring the update, but in the case of a mandatory update, it seems like the prompt should be modal since you have no choice but to continue. Would an end-user ever expect to dismiss a non-modal dialog, only to have it actually force the behavior as if they accepted the prompt?

We had received feedback about this behavior on the React Native plugin, and ended up making the dialog modal/non-dismissable, so the end-user needed to click a button when an update prompt is displayed. Personally, I like this behavior, and its consistent with how we behave on iOS.

CodePush isn't compatible with cordova-plugin-crypt-file

Hi,

I'm using Cordova and codepush with the latest versions.

Here's the plugins that i additinaly used:

code-push 1.6.0-beta "CodePushAcquisition"
com.phonegap.plugins.oauthio 0.2.1 "OAuth.io"
com.verso.cordova.clipboard 0.1.0 "Clipboard"
cordova-instagram-plugin 0.5.3 "Instagram"
cordova-plugin-app-version 0.1.8 "AppVersion"
cordova-plugin-code-push 1.5.1-beta "CodePush"
cordova-plugin-crypt-file 0.0.1 "CordovaCrypt"
cordova-plugin-customurlscheme 4.1.3 "Custom URL scheme"
cordova-plugin-device 1.1.1 "Device"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-file 4.1.1 "File"
cordova-plugin-file-transfer 1.5.0 "File Transfer"
cordova-plugin-globalization 1.0.2 "Globalization"
cordova-plugin-google-analytics 0.8.1 "Google Universal Analytics Plugin"
cordova-plugin-inappbrowser 1.3.1-dev "InAppBrowser"
cordova-plugin-splashscreen 3.1.0 "Splashscreen"
cordova-plugin-statusbar 2.1.1 "StatusBar"
cordova-plugin-whitelist 1.2.1 "Whitelist"
cordova-plugin-x-socialsharing 5.0.10 "SocialSharing"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
org.apache.cordova.console 0.2.10 "Console"
org.apache.cordova.inappbrowser 0.4.1-dev "InAppBrowser"
org.apache.cordova.plugin.ActivityIndicator 1.0.0 "Activity Indicator"
org.apache.cordova.vibration 0.3.10-dev "Vibration"
phonegap-plugin-push 1.5.3 "PushPlugin"

When i'm using codePush.sync() command on deviceready it downloads the package and get Preinstall failure error when it's started to install

Here you can see the console log that i catched via Chrome: http://imgur.com/7i74s1z

I suspect that CordovaCrypt plugin cause this because it's encrypting all files when i use "cordova prepare" command. (It's decrypting that files when application is running)

Any suggestions that you can give me?

Does the plugin store updates?

Hi, i've implemented codepush into our app and everything seems to be working well with the exception of killing the app and restarting. Is there anything specific i need to do to ensure that the app starts from the most recently downloaded update as opposed to the app store version? what's happening now is it will load the app store version and fetch the download for the update.

Info that might be important, we're using the lastest codepush version and cordova 5.4.0.

My code for handling the update is pretty standard:

btnHandler = function(){
    window.codePush.sync(
        function (syncStatus) {},
        {
            updateDialog: true, 
            installMode: InstallMode.IMMEDIATE,
            ignoreFailedUpdates: false
        },
        function (downloadProgress) {
            console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes + " bytes.");
        }
    );
}

codePush sync SyncStatus before download function

Can add a SyncStatus before download?
because if I click continue button for update alert.
I can do anything on this page and change another page.
but I want to show my loading function to limit user touch screem.

sorry my bad english.

Internal server error for code-push release

I am testing code-push for new ionic app. I followed the guide and everything is setup correctly.

  1. I ran following command and got the internal server error.
    code-push release codepushApp "platforms/android/assets/www" "0.0.2" --mandatory
    Upload progress:[==================================================] 100% 0.0s
    [Error] Internal Server Error

I have tried this 4-5 times at least and every time, it's the same issue. It uploads zip file and once upload is done, Internal Server error is shown. In case, it makes any difference, I am trying to upload it from India.

  1. In case, I try to release single file or only templates folder, then it uploads successfully.
    code-push release codepushApp "platforms/android/assets/www/templates/tab-dash.html" "0.0.2" --mandatory
    Upload progress:[==================================================] 100% 0.0s
    Successfully released an update containing the "platforms/android/assets/www/templates/tab-dash.html" file to the "Staging" deployment of the "codepushApp" app.

Now, problem is when mobile app tries to update to new version, it gives error. If, it is single file, it gives error - Cannot unzip file.
If, it is templates folder - It gives error. - Start page of application not found.

Can we have some more details returned, instead of just Internal Server error.

Update Getting Started config.xml editing for iOS

Walking through the Getting Started documentation on my iOS device, I was not successful out of the box for the following reasons:

  1. <access origin="https://codepush.azurewebsites.net/" /> didn't work on iOS, I needed to remove the trailing /
  2. I also needed to add <access origin="https://codepush.blob.core.windows.net" />

CodePush + Ionic livereload doesn't work

The CodePush plugin doesn't work within the context of an app that was deployed via Ionic livereload (e.g. ionic emulate android -l), due to the fact that Ionic's livereload functionality actually "converts" your app into a "hosted app" (i.e. the app is requesting the content from your dev machine as opposed to running it locally on the device), at which point, the WebView enforces CORS. The app itself will still work, but because the CodePush server doesn't enable CORS (by returning the proper headers), the call to either checkForUpdate or sync will fail, because the server isn't explicitly granting access to the client.

In the non-livereload case, the <access> elements in config.xml and the browser's CSP tag determine which domains the app can access, but unfortunately, in the livereload case, these are ignored, and CORS is enforced. This appears to be a known issue and we should investigate whether there is a workaround that doesn't require us to modify the server purely for debugging purposes.

Additionally, we should update our README and/or the error message we display in the CLI to make this limitation much more clear than it currently is. If we can't figure out a workaround, maybe our plugin could detect that it's running in hosted mode (by examining the current URL on the native side?), and effectively "disable" itself so that API calls no-op as opposed to fail.

This is somewhat related to #28, since devs would use livereload as a design-time/debugging tool, and ideally, CodePush wouldn't flat out fail in this case, as opposed to something more graceful/intuitive.

Incremental diff update fails on iOS

Steps to reproduce:

  1. Create new project.
  2. Install update 1 on iOS.
  3. Install update 2 on iOS. (make sure it contains a diff manifest).

Expected:
Update succeeded.

Actual:
Navigation to the updated version does not occur at update time, only at restart time. Initial investigation shows there might be a timing issue (native side does not find the package start page). More investigation is needed.

Need improve the user experience

1, User need to know what's updated
2, Provide the API to show user the package download progress dialog(user should be able to cancel download it if not a mandatory update)

[iOS] index.html alerts on update install

On iOS I receive the following popups after an update is installed.

I thought this may be related to my CSP:
<meta http-equiv="Content-Security-Policy" content="default-src *; img-src 'self' * data: gap:; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">

                let syncOptions = {
                    installMode: InstallMode.IMMEDIATE,
                    updateDialog: false
                };
                window.codePush.sync(this.syncStatusCallback.bind(this), syncOptions, this.syncStaticDownloadProgress.bind(this));

How can I prevent these popups from displaying?

img_2005
img_2006

code-push 1.8.0-beta "CodePushAcquisition"
cordova-plugin-app-event 1.2.0 "Application Events"
cordova-plugin-app-preferences 0.7.7 "AppPreferences"
cordova-plugin-app-version 0.1.8 "AppVersion"
cordova-plugin-badge 0.7.2 "Badges"
cordova-plugin-code-push 1.5.1-beta "CodePush"
cordova-plugin-console 1.0.2 "Console"
cordova-plugin-contacts 2.0.1 "Contacts"
cordova-plugin-device 1.1.1 "Device"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-directions 0.4.3 "Directions"
cordova-plugin-file 4.1.1 "File"
cordova-plugin-file-transfer 1.5.0 "File Transfer"
cordova-plugin-geolocation 2.1.0 "Geolocation"
cordova-plugin-inappbrowser 1.2.1 "InAppBrowser"
cordova-plugin-queries-schemes 0.1.1 "App Queries Strings"
cordova-plugin-splashscreen 3.2.0 "Splashscreen"
cordova-plugin-statusbar 2.1.2 "StatusBar"
cordova-plugin-whitelist 1.2.1 "Whitelist"
cordova-plugin-x-socialsharing 5.0.11 "SocialSharing"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
ionic-plugin-keyboard 2.0.1 "Keyboard"
phonegap-plugin-push 1.6.0 "PushPlugin"

add download size info to remotePackage

there are description and packageSize that are undefined. i think it'd be great if you can tell the user before hand what he can expect size-wise.

// current remotePackage dump
appVersion: "0.4.32"
deploymentKey: "8960f81c-xxx"
description: undefined
downloadUrl: "https://codepush.blob.core.windows.net/storagev2/xxx"
failedInstall: false
isMandatory: false
label: "v3"
packageHash: "fbc201670xxx"
packageSize: undefined

FileUploadOption in fileTransfer.d.ts

Hi,
I've encountered an issue trying to compile my TypeScript code envolving the cordova file transfer plugin.

interface FileUploadOptions {
    ...

    /** A map of header name/header values. Use an array to specify more than one value. */
    headers?: Object[];
}

Shouldn't it be:
headers?: Object;
instead? This way is working fine. I looked up the File Transfer Docs, (even if it's not updated) and doesn't mention array object in the headers param.

I guess the same is for FileDownloadOptions

Am i missing something?

Thank you,
Bye

deploymentKey override not working

I have left my config.xml file with blank strings for the CodePushDeploymentKey. In code I then determine what the appropriate deploymentKey is and then use the syncOptions method to set the key.

When I run the app, the correct key is set. I get the "Checking for update" status. Then in the logs I see:

ERROR: [CodePush] Could not get the CodePush configuration. Please check your config.xml file.
ERROR: [CodePush] An error occurred during sync.

I thought the whole point of setting the value in the syncOptions was to manually be able to set the key?

 <platform name="android">
        <preference name="CodePushDeploymentKey" value="" />

 <platform name="ios">
        <preference name="CodePushDeploymentKey" value="" />
    getCodePushKey(): string {
        if (this.device.isAndroid) {
            if (AppConstants.IsDebugMode)
                return ''; // staging
            else
                return ''; // production
        }
        else if (this.device.isIos) {
            if (AppConstants.IsDebugMode)
                return ''; // staging
            else
                return ''; // production
        }

        return undefined;
    }


  let syncOptions = {
                    installMode: InstallMode.IMMEDIATE,
                    updateDialog: false,
                    deploymentKey: this.getCodePushKey(),
                };
                window.codePush.sync(this.syncStatusCallback.bind(this), syncOptions, this.syncStaticDownloadProgress.bind(this));

Can't build on [email protected]

requirements:

cordova platform add [email protected]

i get the following build error:

No visible @interface for 'UIView' declares the selector 'loadRequest:'

- (void)loadURL:(NSURL*)url {
    [((CDVViewController *)self.viewController).webView loadRequest:[NSURLRequest requestWithURL:url]];
}

Marshmallow on-demand permissions on [email protected]

As soon as I'm about to install the OTA update, I'm asked to allow file storage permissions on the device. This is rather ugly and can turn users away from updating.

Probably not entirely a code-push, but maybe others stumble upon the same issue.

Can this storage permission be omitted with Marshmallow somehow? declaring in the AndroidManifest or something?

screenshot_20160125-173154

Deps not installed with no platforms

When running

cordova plugin add cordova-plugin-code-push

No dependencies (code-push, cordova-plugin-file-transfer, etc.) are installed if there are no platforms added to the cordova project.

ionic plugin add cordova-plugin-code-push
Fetching plugin "cordova-plugin-code-push" via npm
Running command: "C:\Program Files\nodejs\node.exe" c:\Users\dylan.vdmerwe\Projects\GraduateApp\hooks\after_plugin_add\010_register_plugin.js c:\Users\dylan.vdmerwe\Projects\GraduateApp
Saving plugin to package.json file

The plugins are installed when a platform is added. But I believe the deps should be installed regardless of any platform being added.

Remove plugin process should work the same way.

CodePush-ed apps always navigate to the start page when restarted [Android]

Repro Steps:

  1. Install CodePush app update
  2. Navigate to a different page in the app
  3. Press the home button (send app to background)
  4. Re-enter the app

Result:

Web view does not re-open in the current page, but navigates back to the start page due to https://github.com/Microsoft/cordova-plugin-code-push/blob/master/src/android/CodePush.java#L324

This behaviour is unique to CodePush-ed apps. A normal cordova app will re-open in the current page before being sent to the background. Also, the behavior only appears for apps that have already been updated once or more via CodePush, it does not occur If the app is a fresh install (from Play Store).

The remote package does not contain a download URL.

If I create and install a new version of my application with Ionic for android including cordova-plugin-code-push 1.5.1-beta "CodePush",
*BEFORE * I release any updates via code-push, I get the following error when client invokes window.codePush.sync():

Checking for update.
[CodePush] An update is available. {"failedInstall":false}
Downloading package.
[CodePush] Downloading update package
[CodePush] The remote package does not contain a download URL.
[CodePush] An error occurred during sync.
An error occured while checking for updates

It should return SyncStatus.UP_TO_DATE. When I release an update, it updates, and then it works normal, even if there are no new updates.

sample application

Hello I'm trying the sample application and testing it with VS Android simulator. First, can we use simulator for testing the codepush ?

My app identifies that there is an update when I click update button then its error out. I can see that file is getting downloaded by debugging the Index.JS

function (downloadProgress) {
console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes + " bytes.");
});

Error is captured here

 case SyncStatus.ERROR:
                    app.displayMessage("An error occured while checking for updates");
                    break;

Thanks for your help !

Regards,
Sowmyan

Install logs don't account for mandatoryInstallMode

The logs that are outputted by sync when an update is installed only takes into account the installMode property, and not the new mandatoryInstallMode property. For example, if you install an mandatory update using InstallMode.ON_NEXT_RESUME, but the installMode property was set to InstallMode.ON_NEXT_RESTART, the plugin would incorrectly log "Update is installed and will be run on the next app restart." after installing the mandatory update. The install logic makes it clear why this behavior exists.

This isn't a hugely critical bug, but these logs are pretty important for users to diagnose their update experience, so making it accurate is important. I actually got a bit confused by this when dogfooding the new mandatoryInstallMode property :)

Alert user on application rollback

We are thinking about adding an aditional parameter to apply(), such that the user can optionally be alerted when their application is rolled back to the previous version in case of a bad update. We are also thinking about adding a new flag (potentially to LocalPackage) such that developers can react to the rollback.

[email protected] Cannot call "reportStatus" on undefined

When I try to upload a build to Android, the update downloads successfully and running codePush.restartApplication() loads from the new code. However, when I force kill the app and open it again, I get a console error that says Uncaught TypeError: Cannot read property 'reportStatus' of undefined before any of my app code runs. I'm assuming this is the reportStatus function on the codePush object. My hunch is that the reportStatus function is getting called before the Cordova deviceready event when the codePush object becomes available.

When I downgrade to [email protected], I don't get the error.

I'm using the Crosswalk plugin at version 1.6.0.

switching deployment keys possible?

is switching deployment keys possible or would it mess with the diffing and such?

given there would be ios-production and ios-development.

ios update not working properly

In case of iOS after adding code push plugin all the cordova plugins are working on minimizing the app. Working fine on android.

Windows support?

I'm surprised you are not offering support for your own operating system.
Shouldn't be hard to use WinRT as the technology stack?
Why isn't the plugin not depending on a common Cordova file transfer plugin?

isMandatory always comes true

I did a hot code push without mandatory flag. When I run,
code-push deployment ls

It shows Mandatory: No

But the updateCheck api always returns "isMandatory": true

Can you check on this.

[Android] Stuck on CHECKING_FOR_UPDATE

Once an update has been installed, the next time the app runs and tries to check for an update, it gets stuck on the CHECKING_FOR_UPDATE status and does not move.

It seems as though the checkForUpdate callback does not fire once an update has been installed?

let syncOptions = {
       installMode: InstallMode.IMMEDIATE,
       updateDialog: false
};
window.codePush.sync(this.syncStatusCallback.bind(this), syncOptions, this.syncStaticDownloadProgress.bind(this));
  1. The very first time an app is installed it successfully checks for an update.
  2. Using the sync method, the update is installed and the app restarts as per the InstallMode.
  3. When the app restarts, or any other time the app is killed and restarted, the checkForUpdate callback in the sync method never fires.

I'm working on Android. I've tried with and without Crosswalk.

Your system information:

Cordova CLI: 6.1.0 (cordova-lib@undefined)
Ionic Version: 2.0.0-beta.3
Ionic CLI Version: 2.0.0-beta.22
Ionic App Lib Version: 2.0.0-beta.12
OS:
Node Version: v5.7.0

code-push 1.8.0-beta "CodePushAcquisition"
cordova-plugin-app-event 1.2.0 "Application Events"
cordova-plugin-app-preferences 0.7.7 "AppPreferences"
cordova-plugin-app-version 0.1.8 "AppVersion"
cordova-plugin-badge 0.7.2 "Badges"
cordova-plugin-code-push 1.5.1-beta "CodePush"
cordova-plugin-console 1.0.2 "Console"
cordova-plugin-contacts 2.0.1 "Contacts"
cordova-plugin-device 1.1.1 "Device"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-directions 0.4.3 "Directions"
cordova-plugin-file 4.1.1 "File"
cordova-plugin-file-transfer 1.5.0 "File Transfer"
cordova-plugin-geolocation 2.1.0 "Geolocation"
cordova-plugin-inappbrowser 1.2.1 "InAppBrowser"
cordova-plugin-queries-schemes 0.1.1 "App Queries Strings"
cordova-plugin-splashscreen 3.2.0 "Splashscreen"
cordova-plugin-statusbar 2.1.2 "StatusBar"
cordova-plugin-whitelist 1.2.1 "Whitelist"
cordova-plugin-x-socialsharing 5.0.11 "SocialSharing"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
ionic-plugin-keyboard 2.0.1 "Keyboard"
phonegap-plugin-push 1.6.0 "PushPlugin"

Cordova WKWebview Support

I am pulling out my hair trying to find a Cordova solution that will allow for hot code updates, as well as take advantage of the vastly more performant WKWebview. I have tried the following plugins without much luck. I realize since each of these plugins alter the way the application code is loaded, compatibility may not be so trivial. Has there been any experimental setups? Any insight or at least nudges in the right direction would be much appreciated!

https://github.com/Telerik-Verified-Plugins/WKWebView
https://github.com/apache/cordova-plugin-wkwebview-engine
https://github.com/apache/cordova-plugins/tree/master/wkwebview-engine-localhost

Not sure if this helps, but here is a related issue with a similar plugin to code push nordnet/cordova-hot-code-push#42

[email protected] breaks CodePush on Android

If you upgrade the cordova-plugin-file plugin to the latest release (4.2.0), and try to sync a CodePush update on Android, the following error is logged to the console when the plugin attempts to install the update: "Could not get application subdirectory".

This error is coming from here, so something seems to have regressed in the logic that detects the directory that the CodePush update should be written to. The release notes for 4.2.0 indicate that a change was made to the resolveLocalFileSystemURL method on Android, which is exactly the method that is failing, so this commit may provide a pointer into the issue.

As soon as I downgrade the cordoba-plugin-file plugin back to 4.1.1 everything works again. I didn't appear to have any issues on iOS, so it seems like the problem is isolated to just Android. The release notes for 4.2.0 don't indicate any changes to resolveLocalFileSystemURL on iOS, so that seemingly makes sense.

Build instead of Prepare

Normally cordova prepare would be enough however, for example, Ionic 2 requires a compilation step to compile (using gulp) TypeScript and SCSS to create the www directory.

When using the code-push release-cordova command it runs cordova prepare for you, however with Ionic 2 no new changes would be compiled into the platform's www directory.

Maybe think about running a complete cordova build step in order to ensure all scripts and everything is ready for the appropriate platform for the release-cordova command?

Update package

I'm with a problem in the update after update it installs what was downloaded but after you close and open the application sometimes it shows again that has update, or whether it is the same update .
my code:
var onPackageDownloaded = function (localPackage) { localPackage.install(onInstallSuccess, onError); }; var onUpdateCheck = function (remotePackage) { if (!remotePackage) { console.log("The application is up to date."); } else { console.log("A CodePush update is available. Package hash: " + remotePackage.packageHash); $scope.startUpdate = function(){ remotePackage.download(onPackageDownloaded, onError, onProgress); $scope.aceppted = true; } } }; window.codePush.checkForUpdate(onUpdateCheck, onError, deploymentKey);

*Thank you, I'll wait.

appVersion not honoured

As per, https://github.com/Microsoft/code-push/tree/master/cli,
the appStoreVersion parameter indicates the minimum version of the app to which this push is applicable.

I see that from the code, the plugin makes a http request as follows:
https://codepush.azurewebsites.net/updateCheck?deploymentKey=key&appVersion=appversion&packageHash=&isCompanion=false

Ideally it should not update if the appVersion on the hot code push package is greater then the current version being passed in the url. But it seems to still get the update
For example in our case the hot code push package had appVersion set to 0.45.2 and the url being invoked is
https://codepush.azurewebsites.net/updateCheck?deploymentKey=masked-key&appVersion=0.45.0&packageHash=&isCompanion=false

It still get the package and prompts user to update.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.