Giter Club home page Giter Club logo

capacitor-codepush's Introduction

appcenterbanner

Sign up With App Center to use CodePush

Capacitor Plugin for CodePush

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

How does it work?

A Capacitor app is composed of HTML, CSS and JavaScript files and any accompanying images, which are bundled together by the Capacitor 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 Capacitor versions, adding a new plugin) cannot be distributed via CodePush, and therefore, must be updated via the appropriate store(s).

Supported Capacitor Platforms

Tested with these environment

"@capacitor-community/http": "^1.0.0",
"@capacitor/core": "^3.0.0",
"@capacitor/device": "^1.0.0",
"@capacitor/dialog": "^1.0.0",
"@capacitor/filesystem": "^1.0.0"

This Capacitor plugin does not work with Capacitor v2 or older versions.

Getting Started

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

npm i @capacitor-community/http@next @capacitor/device @capacitor/dialog @capacitor/filesystem -D
npm i https://github.com/mapiacompany/capacitor-codepush -D
npx cap sync

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

  1. Add your deployment & code signing (optional) keys to the capacitor.config.json file, making sure to include the right key:

    "Plugins": {
        ... (other plugins)
        "CodePush": {
          "IOS_DEPLOY_KEY": "IOS_DEPLOYMENT_KEY",
          "IOS_PUBLIC_KEY": "APP_SECRET_KEY",
          "ANDROID_DEPLOY_KEY": "ANDROID_DEPLOYMENT_KEY",
          "ANDROID_PUBLIC_KEY": "APP_SECRET_KEY",
          "SERVER_URL": "https://codepush.appcenter.ms/"
        }
    }

    As a reminder, the deployment 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 --app <ownerName>/<appName> --displayKeys, and grab the key for the specific deployment you want to use (e.g. Staging, Production). App IDs can be retrieved by running appcenter apps list.

    The public keys should be generated by you, as should the corresponding private keys.

    # generate private RSA key and write it to private.pem file
    openssl genrsa -out private.pem
    
    # export public key from private.pem into public.pem
    openssl rsa -pubout -in private.pem -out public.pem

    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.

  2. 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 *" />

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.

Plugin Usage

With the Capacitor 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:

import { codePush } from 'capacitor-codepush';
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.

import { codePush } from 'capacitor-codepush';
import { Plugins, AppState } from '@capacitor/core';

const { App } = Plugins;

App.addListener('appStateChange', (state: AppState) => {
    // state.isActive contains the active state
    if (state.isActive) {
        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 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.

# Generic
appcenter codepush release -a <ownerName>/<appName> -c public/

# iOS
appcenter codepush release -a <ownerName>/MyApp-ios -c ios/App/App/public/

# Android
appcenter codepush release -a <ownerName>/MyApp-Android -c android/app/src/main/assets/public/

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 Capacitor 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 command enables such a simple workflow because it understands the standard layout of a Capacitor app, and therefore, can generate your update and know exactly which files to upload. Additionally, in order to support flexible release strategies, the release 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 -a <ownerName>/MyApp-ios -c ios/App/App/public/ -m --description "Modified the header color"

# Release a dev Android build to just 1/4 of your end users
appcenter codepush release -a <ownerName>/MyApp-android -c android/app/src/main/assets/public/ --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 -a <ownerName>/MyApp-android -c android/app/src/main/assets/public/ --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 -a <ownerName>/MyApp-ios -c ios/App/App/public/ -x

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

*NOTE : The path you are to provide to the -c flag might vary depending on the platform or the framework. For example, with an Ionic Capacitor project :

  • Android : ./android/app/src/main/assets/public/
  • iOS : ./ios/App/App/public/

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 cap build before running release command in order to build web assets.

NOTE: for Cordova, we used to use appcenter codepush release-cordova, but with Capacitor we must use appcenter codepush release.

For more details about how the release command works, as well as the various parameters it exposes, refer to the CLI docs.

If you run into any issues, or have any questions/comments/feedback, you can 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(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().then(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();

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().then(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(): Promise<ILocalPackage>;

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.

Example Usage:

codePush.getPendingPackage().then(package => {
    if (package) {
    }
});

codePush.notifyApplicationReady

codePush.notifyApplicationReady(): Promise<void>;

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

sync(syncOptions?: SyncOptions, downloadProgress?: SuccessCallback<DownloadProgress>): Promise<SyncStatus>;

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({ 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:

  • Promise: Resolved 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".

  • onSyncStatusChanged (SuccessCallback<SyncStatus>) - A custom callback that is called when the SyncStatus changes.

  • onSyncError (ErrorCallback) - A custom callback that is called on a sync process error.

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({ 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({ mandatoryInstallMode: InstallMode.ON_NEXT_RESUME });

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

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

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

// Silently check for the update, but
// display a custom downloading UI
// via the SyncStatus and DownloadProgress callbacks
codePush.sync(null, downloadProgress)
    .then(
        (status) => {
            switch (status) {
                case SyncStatus.DOWNLOADING_PACKAGE:
                    // Show "downloading" modal
                    break;
                case SyncStatus.INSTALLING_UPDATE:
                    // Hide "downloading" modal
                    break;
            }
        }
    );

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.

capacitor-codepush's People

Contributors

alexandergoncharov-zz avatar botatoes avatar buptkang avatar cjonsmith avatar clovel avatar dasmajo avatar dlebu avatar geof90 avatar itoys avatar kamengoranchev avatar leo6104 avatar lincolnthree avatar loban avatar lostintangent avatar matrosov-nikita avatar matt-auckland avatar matthiaswenz avatar msftgits avatar nicktoropov avatar nothankyou1 avatar phyr0s avatar rub8n avatar ruslan-bikkinin avatar ryuyu avatar semantic-release-bot avatar sergey-akhalkov avatar shishirx34 avatar vially 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

capacitor-codepush's Issues

iOS An error occurred when trying to get the hash of the binary contents

Description

iOS, iPhone 12 Mini Simulator + Real Device iPhone 12 Mini

First run, I have deployed several updates to codepush "development" deployment with a target binary of -t '^0.0.0'

appcenter codepush release --app xxx/xxx-xxx -d development -t '^0.0.0' -c dist/

and I initialise it like this:

if (isNative) {
    const { codePush } = await import('capacitor-codepush')
    const { App } = await import('@capacitor/app')

    otaUpdates.sync = () => {
      $log.debug('OTA: Running sync')

      codePush.sync({
        installMode: 'ON_NEXT_RESUME'
      })
    }

    // When the app is brought back to the foreground, let's check for an update
    App.addListener('appStateChange', ({ isActive }) => {
      $log.debug('Native app state changed. Is active?', isActive)

      if (isActive) {
        otaUpdates.sync()
      }
    })

    // Run on first launch
    otaUpdates.sync()
}

Reproduction

⚡️  [log] - OTA: Running sync
⚡️  To Native ->  CodePush notifyApplicationReady 126941029
⚡️  TO JS undefined
⚡️  To Native ->  CodePush getDeploymentKey 126941030
⚡️  TO JS {"value":"xxx-hidden-for-issue-xxx"}

⚡️  To Native ->  CodePush getServerURL 126941032
⚡️  TO JS {"value":"https:\/\/codepush.appcenter.ms\/"}

⚡️  To Native ->  CodePush notifyApplicationReady 126941035

⚡️  To Native ->  CodePush getAppVersion 126941040
⚡️  TO JS {"value":"0.5.0"}

⚡️  To Native ->  CodePush getBinaryHash 126941041
ERROR MESSAGE:  {"errorMessage":"An error occurred when trying to get the hash of the binary contents. ","message":"An error occurred when trying to get the hash of the binary contents. "}

⚡️  [error] - {"errorMessage":"An error occurred when trying to get the hash of the binary contents. ","message":"An error occurred when trying to get the hash of the binary contents. "}
⚡️  [error] - [CodePush] Could not get binary hash.Error: Could not get binary hash. 

⚡️  To Native ->  CodePush getAppVersion 126941042
⚡️  TO JS {"value":"0.5.0"}

Additional Information

  • "capacitor-codepush": "github:mapiacompany/capacitor-codepush" (updated today)
  • List of installed plugins:
    "@capacitor-community/http": "1.0.0-alpha.3",
    "@capacitor/android": "3.0.0-rc.0",
    "@capacitor/app": "0.3.6",
    "@capacitor/browser": "0.4.6",
    "@capacitor/camera": "0.4.3",
    "@capacitor/core": "3.0.0-rc.0",
    "@capacitor/device": "0.5.6",
    "@capacitor/dialog": "0.4.6",
    "@capacitor/ios": "3.0.0-rc.0",
    "@capacitor/keyboard": "0.5.6",
    "@capacitor/push-notifications": "0.3.6",
    "@capacitor/splash-screen": "0.3.6",
    "@capacitor/status-bar": "0.4.6",

Default `www` is hardcoded and required

Description

When building with Angular/Ionic/Capacitor for Android, the final assets output is located in ./android/app/src/main/assets/public. The path used in the AppCenter CLI updateContentsPath flag, or -c is apparently relevant to the checks performed internally (or maybe used to name the resulting zip file.) Therefore, executing appcenter codepush release -a "whatever" -c "./android/app/src/main/assets/public" prevents the update files from being found. If you move the files to a www folder (or rename public -> www, it works.

tl;dr www is hardcoded. If the resulting extracted dir is based on the zip filename, that should be used, or otherwise expose a config.

Add additional maintainers?

I can't thank you enough for your initial work on this @leo6104.

It seems now however that there are several useful PRs awaiting merge for a couple of months now.

If you have less time to maintain/review these, would it be beneficial adding active contributors such as @Clovel to keep this fork moving?

Waiting for @capacitor/filesystem next release

Currenctly, @capacitor/filesystem 0.3.1 has problems

  1. Filesystem.copy in Android
  2. Filesystem.rmdir in iOS

It doesn't give Promise.resolve signal from native side.

I open issue & create PR for them. It will be released to next version 0.3.2

Waiting for next release.

Plugin Error

appcenter codepush release -a salem/salemandroid -c ./android/app/src/main/assets/public/ --target-binary-version "~1.0" -d Production
Error: Deployment "Production" does not exist.

Will this work in an ionic 5/capacitor 3/angular/firebase project?

Just a quick question if this should work in an ionic 5/capacitor 3/angular/firebase project to have the same functionality as provided by Ionic Appflow Live Updates. Just to be sure if this is viable for my use case before I dive in deeper trying to implement it. Thank you 🙏 .

CodePush is not implemented on Android

Description

I am trying to run codePush.sync() on button click to try things out. However I get the following error:

CodePush plugin is not implemented on Android How do I resolve this issue?

These are my plugins from capcitor.config.json:

includePlugins: [
    'cordova-plugin-file',
    'cordova-plugin-advanced-http',
    '@ionic-native/http',
    '@capacitor/geolocation',
    '@capacitor/app',
    '@capacitor/filesystem',
    '@capacitor/dialog',
    '@capacitor/device',
    '@capacitor-community/http',
    'capacitor-codepush',
  ],

Here is the capacitor.plugins.json:

[
	{
		"pkg": "@capacitor/geolocation",
		"classpath": "com.capacitorjs.plugins.geolocation.GeolocationPlugin"
	},
	{
		"pkg": "@capacitor/app",
		"classpath": "com.capacitorjs.plugins.app.AppPlugin"
	},
	{
		"pkg": "@capacitor/filesystem",
		"classpath": "com.capacitorjs.plugins.filesystem.FilesystemPlugin"
	},
	{
		"pkg": "@capacitor/dialog",
		"classpath": "com.capacitorjs.plugins.dialog.DialogPlugin"
	},
	{
		"pkg": "@capacitor/device",
		"classpath": "com.capacitorjs.plugins.device.DevicePlugin"
	},
	{
		"pkg": "@capacitor-community/http",
		"classpath": "com.getcapacitor.plugin.http.Http"
	},
	{
		"pkg": "capacitor-codepush",
		"classpath": "com.microsoft.capacitor.CodePush"
	}
]

Dependencies:

"dependencies": {
    "@capacitor-community/http": "https://github.com/leo6104/capacitor-community-http.git#dist",
    "@capacitor/device": "^0.5.6",
    "@capacitor/dialog": "^0.4.6",
    "@capacitor/filesystem": "^0.5.2",
    "capacitor-codepush": "https://github.com/mapiacompany/capacitor-codepush",
    "code-push": "^4.0.4"
  }

Public key was provided but there is no JWT signature within app bundle to verify

E/Capacitor/Console: File: http://localhost/vendor.js - Line 131045 - Msg: [CodePush] Error! Public key was provided but there is no JWT signature within app bundle to verify. Possible reasons, why that might happen:
1. You've been released CodePush bundle update using version of CodePush CLI that is not support code signing.
2. You've been released CodePush bundle update without providing --privateKeyPath option.. StackTrace: Error: Error! Public key was provided but there is no JWT signature within app bundle to verify. Possible reasons, why that might happen:
1. You've been released CodePush bundle update using version of CodePush CLI that is not support code signing.
2. You've been released CodePush bundle update without providing --privateKeyPath option.
at verify (http://localhost/vendor.js:131531:32)
at http://localhost/vendor.js:131573:21
at LocalPackage. (http://localhost/vendor.js:131592:17)
at Generator.next ()
at fulfilled (http://localhost/vendor.js:131438:58)
at ZoneDelegate.invoke (http://localhost/polyfills.js:436:30)
at Zone.run (http://localhost/polyfills.js:196:47)
at http://localhost/polyfills.js:1354:38
at ZoneDelegate.invokeTask (http://localhost/polyfills.js:470:35)
at Zone.runTask (http://localhost/polyfills.js:241:51)

NOTE, I am using the latest appcenter-cli
I also provided a private key path

Can not use `sync` method in script

Description

I want to use CodePush in index.html.
But error occurred : Unhandled Promise Rejection: Error: "CodePush.sync()" is not implemented on iOS

<script src="capacitor.js"></script>
<script>
async function onLoad() {
  const { Plugins } = Capacitor;
  const { CodePush } = Plugins;
  document.addEventListener(
    'deviceready',
    async function () {
      await CodePush.sync()
    },
    false
  );
  document.addEventListener(
    'resume',
    function () {
      ...
    },
    false
  );
  document.addEventListener(
    'pause',
    function () {
      ...
    },
    false
  );
}
</script>
...
<body onload="onLoad()">

So I checked CodePush object
but there is no sync method. also API is different from docs.

image

How can I solve this ?

Additional Information

I use vue2 and capacitor3

ERROR in node_modules/capacitor-codepush/dist/esm/definitions.d.ts:1:13 - error TS1005: '=' expected.

ERROR in node_modules/capacitor-codepush/dist/esm/definitions.d.ts:1:13 - error TS1005: '=' expected.

1 import type { NativeCodePushPlugin } from "./nativeCodePushPlugin";
~
node_modules/capacitor-codepush/dist/esm/definitions.d.ts:1:43 - error TS1005: ';' expected.

1 import type { NativeCodePushPlugin } from "./nativeCodePushPlugin";
~~~~~~~~~~~~~~~~~~~~~~~~

"dependencies": {
"@agm/core": "^1.1.0",
"@angular/animations": "^8.2.13",
"@angular/cdk": "^8.2.3",
"@angular/common": "^8.2.13",
"@angular/compiler": "^8.2.13",
"@angular/core": "^8.2.13",
"@angular/fire": "^5.4.2",
"@angular/forms": "^8.2.13",
"@angular/material": "^8.2.3",
"@angular/platform-browser": "^8.2.13",
"@angular/platform-browser-dynamic": "^8.2.13",
"@angular/pwa": "^0.901.5",
"@angular/router": "^8.2.13",
"@angular/service-worker": "^8.2.13",
"@capacitor-community/http": "^0.3.0",
"@capacitor/android": "^2.4.7",
"@capacitor/core": "^2.4.7",
"@capacitor/dialog": "^0.4.6",
"@capacitor/filesystem": "^0.5.2",
"@ionic-native/android-permissions": "^5.29.0",
"@ionic-native/app-version": "^5.31.1",
"@ionic-native/core": "^5.25.0",
"@ionic-native/diagnostic": "^5.29.0",
"@ionic-native/file-opener": "^5.28.0",
"@ionic-native/firebase-config": "^5.31.1",
"@ionic-native/geolocation": "^5.29.0",
"@ionic-native/in-app-browser": "^5.28.0",
"@ionic-native/location-accuracy": "^5.29.0",
"@ionic-native/screen-orientation": "^5.28.0",
"@ionic-native/social-sharing": "^5.25.0",
"@ionic-native/splash-screen": "^5.25.0",
"@ionic-native/status-bar": "^5.28.0",
"@ionic/angular": "^5.6.3",
"@ionic/pwa-elements": "^3.0.1",
"@ionic/storage": "2.2.0",
"@nebular/eva-icons": "4.6.0",
"@nebular/theme": "4.6.0",
"@ng-select/ng-select": "^3.7.3",
"@ngxs/store": "^3.6.2",
"@sentry/browser": "^5.22.3",
"angular-fire-schematics": "^1.0.0",
"angular-otp-box": "^1.0.1",
"angularx-qrcode": "^2.1.1",
"blob-util": "^2.0.2",
"blueimp-canvas-to-blob": "^3.28.0",
"capacitor-codepush": "https://github.com/mapiacompany/capacitor-codepush",
"classlist.js": "^1.1.20150312",
"cordova-browser": "^6.0.0",
"cordova-plugin-android-permissions": "^1.1.0",
"cordova-plugin-androidx-adapter": "^1.1.1",
"cordova-plugin-app-version": "^0.1.12",
"cordova-plugin-badge": "^0.8.8",
"cordova-plugin-file-opener2": "^3.0.4",
"cordova-plugin-firebase-analytics": "4.4.1",
"cordova-plugin-firebase-config": "^5.0.0",
"cordova-plugin-firebase-inappmessaging": "^3.4.0",
"cordova-plugin-geolocation": "^4.1.0",
"cordova-plugin-inappbrowser": "^5.0.0",
"cordova-plugin-ionic": "5.4.7",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^4.2.1",
"cordova-plugin-request-location-accuracy": "^2.3.0",
"cordova-plugin-screen-orientation": "^3.0.2",
"cordova-plugin-splashscreen": "^5.0.3",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-plugin-x-socialsharing": "^5.6.5",
"cordova-sqlite-storage": "^5.1.0",
"cordova-support-android-plugin": "^1.0.2",
"cordova.plugins.diagnostic": "^6.0.2",
"core-js": "^2.5.4",
"crypto-js": "^3.3.0",
"device-uuid": "^1.0.4",
"es6-promise-plugin": "^4.2.2",
"eva-icons": "1.1.2",
"firebase": "^6.6.2",
"hammerjs": "^2.0.8",
"intl": "^1.2.5",
"jetifier": "^1.6.6",
"lodash": "^1.0.0",
"lottie-web": "^5.7.5",
"ng-connection-service": "^1.0.4",
"ng-image-slider": "2.5.0",
"ng-lazyload-image": "^9.1.0",
"ng-navigator-share": "^1.0.3",
"ng-zorro-antd": "^8.5.2",
"ngx-cookie-service": "^2.4.0",
"ngx-image-compress": "^8.0.4",
"ngx-infinite-scroll": "^9.1.0",
"ngx-lottie": "^6.4.0",
"ngx-mask": "^8.2.0",
"ngx-snackbar": "^2.0.1",
"ngx-timeago": "^1.0.4",
"pdfmake": "^0.1.66",
"primeng": "^8.1.1",
"rxjs": "6.5.2",
"rxjs-compat": "6.3.0",
"time-ago-pipe": "^1.3.2",
"tslib": "^1.11.2",
"web-animations-js": "^2.3.2",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/architect": "^0.803.29",
"@angular-devkit/build-angular": "^0.803.29",
"@angular/cli": "^8.3.26",
"@angular/compiler-cli": "^8.2.13",
"@angular/language-service": "^8.2.13",
"@capacitor/cli": "^2.4.6",
"@ionic/angular-toolkit": "^2.3.3",
"@ionic/lab": "3.0.1",
"@ngxs/devtools-plugin": "^3.6.2",
"@ngxs/logger-plugin": "^3.6.2",
"@types/crypto-js": "^3.1.45",
"@types/googlemaps": "^3.39.13",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/lodash": "^4.14.161",
"@types/node": "~8.9.4",
"@types/swiper": "^5.3.0",
"codelyzer": "^5.2.2",
"cordova-plugin-androidx": "^2.0.0",
"cordova-plugin-device": "^2.0.3",
"gulp": "^4.0.2",
"gulp-gzip": "^1.4.2",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.5.3",
"protractor": "^5.4.4",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
},
"cordova": {
"plugins": {
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
"cordova-plugin-x-socialsharing": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-base64-to-gallery": {},
"cordova-plugin-fcm-with-dependecy-updated": {}
},
"platforms": [
"android"
]
}

Publish on NPM

Will this package be published to NPM? Using Yarn v2, I'm having difficulties adding a package from the GitHub url (it expects the branch to be called "master" - the option to customize will come in Yarn v3).

I noticed another capacitor-codepush on npmjs.com. Have there been any attempts to contact that package publisher and consolidate efforts?

[Critical] Android native updates do not override downloaded CodePush bundle for prior versions.

Description

When app is updated via streaming, if a CodePush update was previously downloaded, it will still be used instead of using the new native bundled code.

Reproduction

  1. Install app version 1.0.0
  2. Prepare a codepush release for 1.0.0 and make sure it is installed via codepush.
  3. Stream / update app version 1.0.1 via native build (adb install -r path/to/release.apk)
  4. The app native version will be 1.0.1, but the code running will still be 1.0.0 (from codepush)

This seems incorrect, as the bundle should use the newer code from the native install/update.

Thoughts on this?

Additional Information

  • cordova-plugin-code-push version: Latest
  • iOS/Android/Windows version: Android 11 (have not tested with others)
  • Does this reproduce on a debug build or release build? Release build streamed via ADB, not sure about prod install from Play Store yet.
  • Does this reproduce on a simulator, or only on a physical device? Physical device.

"Device" plugin is not implemented on ios. StackTrace: CapacitorException

Description

After installation and build, I always get this error:

[CodePush]  "Device" plugin is not implemented on ios. StackTrace: CapacitorException
createPluginMethod

promiseReactionJob@[native code]
(anonymous function) — index.js:40
(anonymous function) — index.js:40
logError — codePushUtil.js:47
(anonymous function) — codePushUtil.js:59
(anonymous function) — codePush.js:188
generatorResume
rejected — codePush.js:5
promiseReactionJob
index.js:40

The app doesn't crash but apparently there is no way to call execute .sync()

Has anyone managed to run this plugin without errors?

Additional Information

iOS 14.4
Capacitor 3.0

Cannot find module 'capacitor-codepush', webpackMissingModule

Screen Shot 2022-01-21 at 00 20 55

I'm currently facing an error like the image even though the package was already installed in node_modules.

I'm using webpack. I can not find a solution to solve this error.
Someone can help me. Thanks

  • Webpack: 4.39.0
  • React: ^16.9.17
// package.json
"@capacitor/cli": "^3.0.0",
"@capacitor/core": "^3.0.0"
"@capacitor-community/http": "^1.0.0-alpha.5",
"@capacitor/cli": "1.5.2",
"@capacitor/device": "^1.1.2",
"@capacitor/dialog": "^1.0.7",
"@capacitor/filesystem": "^1.1.0",
"capacitor-codepush": "git+https://github.com/mapiacompany/capacitor-codepush.git",

Integrating into a standard javascript app

I apologize, my lack of knowledge of how to build modern Javascript apps is showing.

We have a Capacitor app that uses plain Javascript, without any build tools. This works fine. We're trying to add codepush support and we're running into a problem with how to integrate it into our app.

For Capacitor and its' plugins, we use <script> tags to include the plugin.js files from the various node_modules/.../dist directories.

If we do this with node_modules/capacitor-codepush/dist/plugin.js, we get an error about missing acquisitionSdk. Including node_modules/code-push/script/acquisition-sdk.js doesn't help.

Ok, so maybe there are a bunch of dependencies? We tried using rollup to see if we could get that to work, but cannot. Using this simple input file:

import { codePush } from 'capacitor-codepush';

console.log("hello");

we get [!] Error: Invalid value "iife" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.

Any help would be appreciated.

CodePush.addListener() not implemented

Description

Currently there is no way to register for/observe status updates from the sync process. The method exists, but it does not look like there is anything publishing events on the "codePushStatus" channel:

https://github.com/mapiacompany/capacitor-codepush/blob/capacitor/src/nativeCodePushPlugin.ts#L70

Reproduction

Register a listener. Nothing happens :) Also it does not appear this is referenced anywhere in the project code (doing a search for 'codePushStatus' only results are this interface.)

CodePush causes uncaught exceptions when previewing project on a web browser

Description

When debugging or developing an app using a web browser (for example for styling development), CodePush throws an uncaught exception that does not come from the app's source code.

Additional Information

This issue does not happen with other Capacitor plugins that are "mobile-only". A good example is the Firebase notification plugin.

Screenshots

Exception :

Capture_d_écran_2021-06-30_à_15 39 29

Code extract :
Capture_d_écran_2021-06-30_à_15 40 08

Is this package still maintained?

I've noticed that questions aren't being answered and PRs not merged for a 4-5 months. We plan to start using Capacitor with Appcenter (coming from Cordova) but we need something more stable than this fork.

If this is an abandoned fork, then we would probably be happy to take responsibility for creating a fork or a version which is properly published to NPM, with some commitment to keeping the community active and the package maintained.

CommonJS or AMD dependencies can cause optimization bailouts.

Hi,

Description

When compiling with Angular > 10 than I get this warning:

...\node_modules\capacitor-codepush\dist\esm\codePush.js depends on 'code-push/script/acquisition-sdk'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Additional Information

  • capacitor-plugin-code-push version: "capacitor-codepush": "git+ssh://[email protected]/mapiacompany/capacitor-codepush.git#037174d2c00fa1a095f1ed2a445a31ccd70815df",
  • List of installed plugins:
  • Capacitor version: Capacitor CLI: 3.5.1
  • iOS/Android/Windows version: Build on win10
  • Does this reproduce on a debug build or release build?
  • Does this reproduce on a simulator, or only on a physical device?

(The more info the faster we will be able to address it!)

Maybe bug: User prompted for Filesystem access

Thanks so much for getting this plugin converted to Capacitor!

Description

After installing and configuring the code-push plugin, doing some preliminary testing seems to show that users are required to accept the following permission prompt:

image

Is this normal, or have I done something wrong? It seems this plugin should be able to function without writing to External storage, but I am not an Android permissions expert.

Reproduction

  1. Ensure update is available in AppCenter
  2. Run the app with this plugin installed
  3. Call codePushUtil.sync()

Additional Information

  • cordova-plugin-code-push version: This repo
  • List of installed plugins:
[info] Found 20 Capacitor plugins for ios:
       @capacitor-community/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       [email protected]
       [email protected]
       [email protected]
[info] Found 2 Cordova plugins for ios:
       [email protected]
       [email protected]
  • Capacitor version: 3.0.0-beta.6
  • iOS/Android/Windows version: iOS 14, Android 11
  • Does this reproduce on a debug build or release build? Both
  • Does this reproduce on a simulator, or only on a physical device? Both

(The more info the faster we will be able to address it!)

Maintenance: Update iOS CAPPluginCall access to use non-deprecated APIs

Description

Per Capacitor team, the NSString, BOOL, and NSNumber accessors for CAPPluginCall will be deprecated going forward, in favor of this api:

https://github.com/ionic-team/capacitor/blob/main/ios/Capacitor/Capacitor/JSTypes.swift
https://github.com/ionic-team/capacitor/blob/main/ios/Capacitor/Capacitor/CAPBridgedJSTypes.h (requires additional import statement)

See: ionic-team/capacitor#4303 (comment)

Resolution steps

The iOS implementation should be refactored to use these new methods:

https://github.com/mapiacompany/capacitor-codepush/blob/capacitor/ios/Plugin/CodePush.m#L177
https://github.com/mapiacompany/capacitor-codepush/blob/capacitor/ios/Plugin/CodePush.m#L190

And other places that reference the deprecated methods.

[NOT A ISSUE] AppCenter CodePush Backend Alternative

Hi, since Cordova retirement on AppCenter and per consequence Capacitor, I started looking for an backend alternative.

I almost started one from scratch, but I found an old (dated 2019) repository made by a guy and one fork with some commits but outdated too (the most recents commits are dependences only). It's pretty outdated since need to use [email protected], but I managed to make it work with latest [email protected] and [email protected] with little adjustments.

I'm currently self-hosting my own CodePush backend and already delivered 224 updates since Oct 30, without rollbacks so far. (I have a small base of users :/)

Since the backend normally works with CodePush and Capacitor I believe it will be a good point to revive that project.

I'm thinking some thing like Integration with OneDrive as "CDN" to host the updates or like so.

HTTP methods fail on iOS due to malformed GET request with body (Native)

Description

It appears that the network code for this plugin is incorrectly constructing get requests.

2021-03-03 15:02:22.938979-0500 App[6904:5522939] Task <A2C990DB-1A87-4124-ABA1-B6141979FD3A>.<3> finished with error [-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" UserInfo={NSLocalizedDescription=resource exceeds maximum size, NSErrorFailingURLStringKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/download, NSErrorFailingURLKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/download, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <A2C990DB-1A87-4124-ABA1-B6141979FD3A>.<3>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A2C990DB-1A87-4124-ABA1-B6141979FD3A>.<3>, NSUnderlyingError=0x282ca1e00 {Error Domain=kCFErrorDomainCFNetwork Code=-1103 "(null)"}}
2021-03-03 15:02:22.943402-0500 App[6904:5522933] GET method must not have a body
2021-03-03 15:02:22.943573-0500 App[6904:5522933] Task <2FBC8F8C-78F4-4BE7-AEB3-E8EA130F2468>.<4> finished with error [-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" UserInfo={NSLocalizedDescription=resource exceeds maximum size, NSErrorFailingURLStringKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/deploy, NSErrorFailingURLKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/deploy, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <2FBC8F8C-78F4-4BE7-AEB3-E8EA130F2468>.<4>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <2FBC8F8C-78F4-4BE7-AEB3-E8EA130F2468>.<4>, NSUnderlyingError=0x282cadbf0 {Error Domain=kCFErrorDomainCFNetwork Code=-1103 "(null)"}}

Reproduction

  1. Update available in AppCenter
  2. Run codePush.sync() on an iOS device.
  3. Inspect device logs.

Additional Information

I am already using your fork of @capacitor-community/http#dist, and the latest plugin code for app other @capacitor/* plugins.

CORS error: cannot download the update.zip file during .sync()

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Description

After #8 the plugin starts and syncs with the appcenter. Nonetheless it cannot download the file, apparently due to cors restrictions.
It does create the destination folder but nothing more.

⚡️  [error] - {"message":"Impossibile aprire il file “update.zip” perché non c'è un file di quel tipo.","errorMessage":"Impossibile aprire il file “update.zip” perché non c'è un file di quel tipo."}
⚡️  [error] - [CodePush]  Origin capacitor://localhost is not allowed by Access-Control-Allow-Origin.. StackTrace: capacitor://localhost/js/chunk-vendors.bfede95a.js:1:58326
generatorResume@[native code]
s@capacitor://localhost/js/chunk-vendors.bfede95a.js:1:57492
promiseReactionJob@[native code]

I tried adding @capacitor-community/http but nothing changes.

Any hints?

The file “currentPackage.json” couldn’t be opened because there is no such file

Description

I created a capacitor project, installed the plugins, and configured the deployment key. From the javascript layer, I invoked the sync() function. I'm getting the following error and the application gets crashed at the end.

ERROR MESSAGE:  {"message":"The file “currentPackage.json” couldn’t be opened because there is no such file.","errorMessage":"The file “currentPackage.json” couldn’t be opened because there is no such file."}
⚡️  [error] - {"message":"The file “currentPackage.json” couldn’t be opened because there is no such file.","errorMessage":"The file “currentPackage.json” couldn’t be opened because there is no such file."}
⚡️  To Native ->  CodePush getAppVersion 52875057
⚡️  TO JS {"value":"1.0"}
⚡️  To Native ->  CodePush getBinaryHash 52875058
ERROR MESSAGE:  {"errorMessage":"An error occurred when trying to get the hash of the binary contents. ","message":"An error occurred when trying to get the hash of the binary contents. "}
⚡️  To Native ->  CodePush getAppVersion 52875059
⚡️  [error] - {"errorMessage":"An error occurred when trying to get the hash of the binary contents. ","message":"An error occurred when trying to get the hash of the binary contents. "}
⚡️  [error] - [CodePush] Could not get binary hash.Error: Could not get binary hash. 
⚡️  TO JS {"value":"1.0"}
⚡️  [log] - [CodePush] Checking for update.
⚡️  To Native ->  Http request 52875060
⚡️  TO JS {"headers":{"Strict-Transport-Security":"max-age=15724800; includeSubDomains","Access-Control-Allow-Origin":"*","Vary":"Accept-Encoding","Content-Type":"application\/json; charset=utf-8","Content-Encoding":"gzip","access-control-allow-methods":"GET","acces
⚡️  To Native ->  CodePush isFailedUpdate 52875061
⚡️  TO JS {"value":0}
⚡️  [log] - [CodePush] An update is available. {"isDownloading":false,"appVersion":"1.0","deploymentKey":"svqcsCjsJhESC0ZmUXYe3nym2mRede7REmeCX","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/5eXOhadabwEgZHnQjkwnW_JlARRK0c894bb4-6419-4a7e-ae5e-6c01025b63ae","isMandatory":false,"label":"v3","packageHash":"048f5e1ca9db0d66c3a9b56c36501db8ab9738a3c27f1002b424cb541bcacca9","packageSize":22793,"failedInstall":0}
⚡️  [log] - [CodePush] Downloading update
⚡️  To Native ->  Filesystem getUri 52875062
⚡️  TO JS {"uri":"file:\/\/\/Users\/\/Library\/Developer\/CoreSimulator\/Devices\/AC8BE0AE-1B17-4507-9CD5-E6098D4B144F\/data\/Containers\/Data\/Application\/E839E370-8FF2-44E8-B97B-0CD4B9EC4EBA\/Documents\/codepush\/download\/update.zip"}
⚡️  To Native ->  Filesystem stat 52875063
ERROR MESSAGE:  {"message":"The file “download” couldn’t be opened because there is no such file.","errorMessage":"The file “download” couldn’t be opened because there is no such file."}
⚡️  [error] - {"message":"The file “download” couldn’t be opened because there is no such file.","errorMessage":"The file “download” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem mkdir 52875064
⚡️  TO JS undefined
⚡️  To Native ->  Filesystem stat 52875065
ERROR MESSAGE:  {"errorMessage":"The file “update.zip” couldn’t be opened because there is no such file.","message":"The file “update.zip” couldn’t be opened because there is no such file."}
⚡️  [error] - {"errorMessage":"The file “update.zip” couldn’t be opened because there is no such file.","message":"The file “update.zip” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Http downloadFile 52875066
⚡️  TO JS {"status":200,"url":"https:\/\/codepush.appcenter.ms\/v0.1\/public\/codepush\/report_status\/deploy","data":"OK","headers":{"access-control-allow-credentials":"false","Strict-Transport-Security":"max-age=15724800; includeSubDomains","Content-Type":"text\/p
⚡️  To Native ->  CodePush reportSucceeded 52875067
⚡️  [log] - [CodePush] Reported status: {"status":0,"appVersion":"1.0","deploymentKey":"svqcsCjsJhESC0ZmUXYe3nym2mRede7REmeCX","lastVersionLabelOrAppVersion":null,"lastVersionDeploymentKey":null}
⚡️  TO JS undefined
File Dest file:///Users/Library/Developer/CoreSimulator/Devices/AC8BE0AE-1B17-4507-9CD5-E6098D4B144F/data/Containers/Data/Application/E839E370-8FF2-44E8-B97B-0CD4B9EC4EBA/Documents/codepush/download/update.zip
⚡️  TO JS {"path":"file:\/\/\/Users/Library\/Developer\/CoreSimulator\/Devices\/AC8BE0AE-1B17-4507-9CD5-E6098D4B144F\/data\/Containers\/Data\/Application\/E839E370-8FF2-44E8-B97B-0CD4B9EC4EBA\/Documents\/codepush\/download\/update.zip"}
Downloaded file file:///Users/Library/Developer/CoreSimulator/Devices/AC8BE0AE-1B17-4507-9CD5-E6098D4B144F/data/Containers/Data/Application/E839E370-8FF2-44E8-B97B-0CD4B9EC4EBA/tmp/CFNetworkDownload_BknJec.tmp
⚡️  To Native ->  CodePush isFailedUpdate 52875068
⚡️  TO JS {"value":0}
⚡️  [log] - [CodePush] Package download success: {"deploymentKey":"svqcsCjsJhESC0ZmUXYe3nym2mRede7REmeCX","label":"v3","appVersion":"1.0","isMandatory":false,"packageHash":"048f5e1ca9db0d66c3a9b56c36501db8ab9738a3c27f1002b424cb541bcacca9","isFirstRun":false,"failedInstall":0,"localPath":"file:///Users/Library/Developer/CoreSimulator/Devices/AC8BE0AE-1B17-4507-9CD5-E6098D4B144F/data/Containers/Data/Application/E839E370-8FF2-44E8-B97B-0CD4B9EC4EBA/Documents/codepush/download/update.zip"}
⚡️  [log] - [CodePush] Installing update
⚡️  To Native ->  Filesystem stat 52875069
⚡️  To Native ->  Http request 52875070
ERROR MESSAGE:  {"message":"The file “unzipped” couldn’t be opened because there is no such file.","errorMessage":"The file “unzipped” couldn’t be opened because there is no such file."}
⚡️  [error] - {"message":"The file “unzipped” couldn’t be opened because there is no such file.","errorMessage":"The file “unzipped” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem mkdir 52875071
⚡️  TO JS undefined
⚡️  To Native ->  Filesystem getUri 52875072
⚡️  TO JS {"uri":"file:\/\/\/Users\/Library\/Developer\/CoreSimulator\/Devices\/AC8BE0AE-1B17-4507-9CD5-E6098D4B144F\/data\/Containers\/Data\/Application\/E839E370-8FF2-44E8-B97B-0CD4B9EC4EBA\/Documents\/codepush\/download\/unzipped\/"}
⚡️  To Native ->  CodePush unzip 52875073
⚡️  TO JS undefined
⚡️  To Native ->  Filesystem stat 52875074
ERROR MESSAGE:  {"message":"The file “hotcodepush.json” couldn’t be opened because there is no such file.","errorMessage":"The file “hotcodepush.json” couldn’t be opened because there is no such file."}
⚡️  To Native ->  ⚡️  [error] - {"message":"The file “hotcodepush.json” couldn’t be opened because there is no such file.","errorMessage":"The file “hotcodepush.json” couldn’t be opened because there is no such file."}
Filesystem stat 52875075
ERROR MESSAGE:  {"errorMessage":"The file “versions” couldn’t be opened because there is no such file.","message":"The file “versions” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem mkdir 52875076
⚡️  [error] - {"errorMessage":"The file “versions” couldn’t be opened because there is no such file.","message":"The file “versions” couldn’t be opened because there is no such file."}
⚡️  TO JS undefined
⚡️  To Native ->  Filesystem stat 52875077
ERROR MESSAGE:  {"errorMessage":"The file “048f5e1ca9db0d66c3a9b56c36501db8ab9738a3c27f1002b424cb541bcacca9” couldn’t be opened because there is no such file.","message":"The file “048f5e1ca9db0d66c3a9b56c36501db8ab9738a3c27f1002b424cb541bcacca9” couldn’t be opened because there is no such file."}
⚡️  [error] - {"errorMessage":"The file “048f5e1ca9db0d66c3a9b56c36501db8ab9738a3c27f1002b424cb541bcacca9” couldn’t be opened because there is no such file.","message":"The file “048f5e1ca9db0d66c3a9b56c36501db8ab9738a3c27f1002b424cb541bcacca9” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem copy 52875078
⚡️  TO JS undefined
⚡️  To Native ->  CodePush getPublicKey 52875079
⚡️  [log] - [CodePush] Applying full update
2021-03-12 10:56:22.857960+0530 App[63556:7336508] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff23d03ab1 _CFThrowFormattedException + 194
	3   CoreFoundation                      0x00007fff23d0e4c6 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.4 + 38
	4   CoreFoundation                      0x00007fff23cced97 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 247
	5   CoreFoundation                      0x00007fff23c6d12b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
	6   CapacitorCodepush                   0x000000010e56ea27 -[CodePushPlugin getPublicKey:] + 167
	7   Capacitor                           0x000000010e4381b6 $s9Capacitor0A6BridgeC12handleJSCall4callyAA0D0V_tFyycfU_ + 1318
	8   Capacitor                           0x000000010e42be8d $sIeg_IeyB_TR + 45
	9   libdispatch.dylib                   0x000000010edf4dd4 _dispatch_call_block_and_release + 12
	10  libdispatch.dylib                   0x000000010edf5d48 _dispatch_client_callout + 8
	11  libdispatch.dylib                   0x000000010edfc5ef _dispatch_lane_serial_drain + 788
	12  libdispatch.dylib                   0x000000010edfd17f _dispatch_lane_invoke + 422
	13  libdispatch.dylib                   0x000000010ee08a4e _dispatch_workloop_worker_thread + 719
	14  libsystem_pthread.dylib             0x00007fff5245f611 _pthread_wqthread + 421
	15  libsystem_pthread.dylib             0x00007fff5245f3fd start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Additional Information

"@capacitor-community/http": "^1.0.0-alpha.2",
"@capacitor/cli": "^3.0.0-rc.0",
"@capacitor/core": "^3.0.0-rc.0",
"@capacitor/device": "^0.5.6",
"@capacitor/dialog": "^0.4.6",
"@capacitor/filesystem": "^0.5.2",
"@capacitor/ios": "^3.0.0-rc.0",
"@capacitor/splash-screen": "^0.3.6",
"capacitor-codepush": "github:mapiacompany/capacitor-codepush"

Repository Info

https://github.com/UserSG/CodePushWithCapacitor.git

Docs Update

This repo is forked from cordova project.

We replace all onSuccess/onFailure callback parameter to Promise-pattern.

Let's update README.md .

Using with other capacitor versions

Does this only work on capacitor 3? I'm interested in implementing with this but the docs are 100% clear on what version of capacitor you need to use. Do I need to upgrade to capacitor 3?

I tried on capacitor 2 and it wouldn't compile in Android studio. When I googled the error message it talked about incompatibility with capacitor 2. I can share more info if that is not the expected behavior.

Error: "Cannot overwrite directory" during install

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Description

After user confirms "Install" (or non-dialog install), the following error occurs during copying of files:

index.js:78 native Filesystem.copy (#35089827):

Object:
{
callbackId: "82559909"
methodName: "copy"
options:
directory: "DATA"
from: "codepush/download/unzipped"
to: "codepush/deploy/versions/e07143b920ba863f8a1d1c909d584963655e6a7df9ee85f7681f0995a76f5ab3"
toDirectory: "DATA"
__proto__: Object
pluginId: "Filesystem"
__proto__: Object
}
    at Object.cap.fromNative (http://10.0.0.3:8100/vendor.js:88789:24)
    at <anonymous>:1:18
logError @ codePushUtil.js:47
push.Yr+L.CodePushUtil.invokeErrorCallback @ codePushUtil.js:59
installError @ localPackage.js:44
(anonymous) @ localPackage.js:70
rejected @ localPackage.js:5
invoke @ zone-evergreen.js:372
onInvoke @ core.js:28579
invoke @ zone-evergreen.js:371
run @ zone-evergreen.js:134
(anonymous) @ zone-evergreen.js:1276
invokeTask @ zone-evergreen.js:406
onInvokeTask @ core.js:28566
invokeTask @ zone-evergreen.js:405
runTask @ zone-evergreen.js:178
drainMicroTaskQueue @ zone-evergreen.js:582
Promise.then (async)
scheduleMicroTask @ zone-evergreen.js:565
scheduleTask @ zone-evergreen.js:396
onScheduleTask @ zone-evergreen.js:283
scheduleTask @ zone-evergreen.js:386
scheduleTask @ zone-evergreen.js:221
scheduleMicroTask @ zone-evergreen.js:241
scheduleResolveOrReject @ zone-evergreen.js:1266
resolvePromise @ zone-evergreen.js:1204
(anonymous) @ zone-evergreen.js:1120
cap.fromNative @ index.js:297
(anonymous) @ VM2627:1
15:22:59.417 codePushUtil.js:47 [CodePush] An error occurred during sync. Cannot overwrite a directory. StackTrace: Error: Cannot overwrite a directory
    at Object.cap.fromNative (http://10.0.0.3:8100/vendor.js:88789:24)
    at <anonymous>:1:18

Reproduction

  1. Ensure update is available in AppCenter
  2. Run the app with this plugin installed
  3. Call codePushUtil.sync()

Additional Information

  • cordova-plugin-code-push version: This repo
  • List of installed plugins:
[info] Found 20 Capacitor plugins for ios:
       @capacitor-community/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       [email protected]
       [email protected]
       [email protected]
[info] Found 2 Cordova plugins for ios:
       [email protected]
       [email protected]
  • Capacitor version: 3.0.0-beta.6
  • iOS/Android/Windows version: iOS 14, Android 11
  • Does this reproduce on a debug build or release build? Both
  • Does this reproduce on a simulator, or only on a physical device? Both

CodePush Error Could not get the package start page

I am testing this on an Ionic/Capacitor/Angular/Firebase project, NOT Cordova.
What I have done so far:

  1. Created new app with appcenter apps create -d <appDisplayName> -o iOS -p Cordova
  2. Created new deployment with appcenter codepush deployment add -a <ownerName>/<appName> Production
  3. Built new app version ready for release with ng build
  4. Released new version with appcenter codepush release -a <ownerName>/<appName> -c ./PATH_TO_BUILD -m -t 1.0 -d Production
  5. The app displays the modal saying new version is available. I click continue to proceed with install.
  6. During the install in Xcode I get the error CodePush Error Could not get the package start page....
  7. I downloaded the update manually from the appcenter website to check it, unzipped it, it has the following file structure: all files are stored one directory, directory name is my angular project name, the files in this directory are all my built project files, everything seems absolutely fine, index.html is included.

If anyone has a suggestion where I got it wrong, please do let me know.

Unable to verify signature for package: PUBLIC_KEY in capacitor.config.json

"CodePush": {
      "IOS_DEPLOY_KEY": "IOS_DEPLOYMENT_KEY",
      "IOS_PUBLIC_KEY": "APP_SECRET_KEY",
      "ANDROID_DEPLOY_KEY": "ANDROID_DEPLOYMENT_KEY",
      "ANDROID_PUBLIC_KEY": "APP_SECRET_KEY",
      "SERVER_URL": "https://codepush.appcenter.ms/"
 }

Hi, in the capacitor.config.json file, what exactly should I put in place of IOS_PUBLIC_KEY and ANDROID_PUBLIC_KEY?
It's mentioned that I put the APP_SECRET_KEY. Is the the one:

<platform name="android">
  <preference name="APP_SECRET" value="key-which-is-shown-here" />
</platform>

^ displayed on appcenter dashboard.

If I put that one, I get the following error:

Unable to verify signature for package: Error: Error occurred while creating the a public keyjava.security.spec.InvalidKeySpecException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key. StackTrace: Error: Unable to verify signature for package: Error: Error occurred while creating the a public keyjava.security.spec.InvalidKeySpecException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key
    at decodeSignatureFail

Report status API error

It has an issue with codePush.reportFailed / codePush.reportSucceeded.
We cannot track the deployment status in AppCenter Dashboard.

It should be fixed.

[CodePush] An error occurred while reporting status: {"status":0,"appVersion":"4.4.4","deploymentKey":"X------------------","lastVersionLabelOrAppVersion":null,"lastVersionDeploymentKey":null} 400: {"status":400,"name":"Error","message":"Missing required body parameter \"release_metadata\""

TypeError: undefined is not an object (evaluating 'window.codePush.reportStatus')

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Description

I'm not sure why this is happening, but a small subset of devices the codePush instance seems unavailable in the window context. Possibly a timing issue? This is strange though because our app waits a solid 4-5s before attempting any CodePush actions.

TypeError: undefined is not an object (evaluating 'window.codePush.reportStatus')
  at ionic:(//localhost:1:71)
  at ? (ionic://localhost/polyfills-es2015.6efff9e9e083b048c166.js:1:40938)
  at runTask(ionic://localhost/polyfills-es2015.6efff9e9e083b048c166.js:1:11465)
  at invokeTask(ionic://localhost/polyfills-es2015.6efff9e9e083b048c166.js:1:17103)

Reproduction

No reproduction available currently. Just production logging messages.

Additional Information

  • cordova-plugin-code-push version: latest
  • List of installed plugins:
  • Cordova version:
  • iOS/Android/Windows version:
  • Does this reproduce on a debug build or release build? release build
  • Does this reproduce on a simulator, or only on a physical device? physical & unknown

(The more info the faster we will be able to address it!)

Android build error: Could not get unknown property 'androidxAppCompatVersion'

Description

Im trying to use this capacitor-codepush in an ionic + capacitor app for Android and it fails when building with this error:

A problem occurred evaluating project ':capacitor-codepush'. Could not get unknown property 'androidxAppCompatVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Reproduction

install latest version of capacitor-codepush, then run:
ng build
npx cap copy android
npx cap open android

The error is fired when the app is indexing in Android Studio.

Additional Information

It only happens to Android, in iOS is working

List of installed plugins:

"@capacitor/core": "^3.2.3"
"@capacitor/device": "^1.0.3"
"@capacitor/dialog": "^1.0.3"
"@capacitor/filesystem": "^1.0.3"
"@capacitor/android": "^3.2.3"

Any help? Thanks in advance

IllegalStateException on Android 7

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Description

Not sure what's happening yet, but some errors occurring in Play Analytics. I will try to investigate.

Reproduction

Screenshot_20210313-091929

Screenshot_20210313-091951

Additional Information

  • cordova-plugin-code-push version: latest
  • List of installed plugins:
  • Cordova version: capacitor 3
  • iOS/Android/Windows version: Android
  • Does this reproduce on a debug build or release build? Release
  • Does this reproduce on a simulator, or only on a physical device? Physical

(The more info the faster we will be able to address it!)

Cannot read property 'onSyncStatusChanged' of undefined

I am trying to implement CodePush functionality on my app. Followed the readme tutorial line by line but I am receiving the following error

Uncaught (in promise): TypeError: Cannot read property 'onSyncStatusChanged' of undefined
TypeError: Cannot read property 'onSyncStatusChanged' of undefined

Project Info

Ionic:

Ionic CLI : 6.16.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.6.8
@angular-devkit/build-angular : 12.0.2
@angular-devkit/schematics : 12.0.2
@angular/cli : 12.0.2
@ionic/angular-toolkit : 4.0.0

Capacitor:

Capacitor CLI : 3.0.0
@capacitor/android : 3.0.1
@capacitor/core : 3.0.0
@capacitor/ios : not installed

Cannot sync the xcode project

Description

Hello and thank you for this great plugin. I have some issue installing it on iOS. When I try to sync the native project I get an error with pods. Specifically, I get:

[error] Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "CapacitorCodepush":
  In Podfile:
    CapacitorCodepush (from `../../node_modules/capacitor-codepush`)

Specs satisfying the `CapacitorCodepush (from `../../node_modules/capacitor-codepush`)` dependency were found, but they required a higher minimum deployment target.

Reproduction

npx cap sync

Additional Information

  • cordova-plugin-code-push version: 1.0.0
  • List of installed plugins: @capacitor-community/fcm, @capacitor-community/firebase-analytics
  • iOS version: Deployment target 12.0

*** Update ***

Only solution so far is to comment out the ios.deployment_target line within the pod specs.

After downloading, while installation, app goes white and says `cordova is not defined`

Description

After downloading, while installation, app goes white and says cordova is not defined

Reproduction

  1. Run app on android
  2. Make minor text changes in the code (i made in index.html)
  3. build, sync and release to codepush via: appcenter codepush release -a ashish141199/Intract-Android -c public/ --target-binary-version "*"
  4. Restart the app, it says "Checking for update" and then Downloaded, will be installed on next restart
  5. When I restart the app, the screen goes white and nothing happens at all. In chrome://inspect I was able to see cordova is not defined and then nothing.

Additional Information

  • cordova-plugin-code-push version:
  • Cordova version: 10.0.0
  • iOS/Android/Windows version: Android 9
  • Does this reproduce on a debug build or release build? both
  • Does this reproduce on a simulator, or only on a physical device? physical device

app rolls back to the version before update after closed and opened again

I am testing this on an Ionic/Capacitor/Angular/Firebase project, NOT Cordova.
What I have done so far:

Created new app with appcenter apps create -d <appDisplayName> -o iOS -p Cordova
Created new deployment with appcenter codepush deployment add -a <ownerName>/<appName> Production
Built new app version ready for release with ionic capacitor build
Released new version with appcenter codepush release -a <ownerName>/<appName> -c ./PATH_TO_BUILD -m -t 1.0 -d Production
In the angular app I have this:

codePush
      .sync(
        {
          installMode: InstallMode.ON_NEXT_RESUME,
          mandatoryInstallMode: InstallMode.IMMEDIATE,
          onSyncStatusChanged: (status) => {
            console.log(status)
          },
        },
        (progress) => {
          console.log(progress)
          );
        }
      )
      .then((status) => {
        console.log(status)
      });

If I make an update available via Codepush, the update downloads and installs, the app restarts, I can see the changes, everything works.
But if I close the app and open it again, it loads in the state before the update was applied.
Tested on emulator and real device. Same behavior.
If anyone has a suggestion where I got it wrong, please do let me know.

*UPDATE: Today I tested also on Android, behavior is exactly the same as on iOS.
*UPDATE 2: Another thing that does not work for me are the callbacks that should be returning the update download progress and onSyncStatusChanged. Even though the update gets downloaded and installed these callbacks never seem to fire.

iOS: Updates extract/say they are installed, but are always rolled back

Description

So, I'm not exactly sure how to report on this one. I've been stuck on it for a few days. I'm wondering if anyone else has observed this behavior.

It seems as if the updates are downloaded and extracted correctly, but when the app restarts, the update is not activated and nothing has changed.

The .sync() method is called again, reporting that the same update is available, but has been rolled back already.

Reproduction

  1. Install app to local iOS device or simulator
  2. Make sure an update is ready on Codepush for the installed bundle version
  3. Start the app & observe logs
  4. Ensure app calls codePush.sync()
  5. Update should install and "waiting until reloaded/restarted" (unless immediate activation is set, at which point it restarts right away)

Screenshot of device filesystem at this point:

Deploy:
image

Download:
image

  1. Restart to activate the update (the update will not be activated at this point, but... continue on)

  2. Ensure application calls "codePush.notifyApplicationReady()"

Device will log:

[Warning] UPDATE: Committing update. (Will not be rolled back.) (vendor-es2015.js, line 86501)
[Warning] UPDATE: Checking for update. (vendor-es2015.js, line 86501)
  1. Ensure app calls codePush.sync() again to verify status
  2. The update will not be available but not activated/not installing, because status is "previously rolled back"

Device will log:

[Log] [CodePush] An update is available. {"isDownloading":false,"appVersion":"10.0.6","deploymentKey":"XXXXXXXXXXX","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/XXXXXXXXXXX","isMandatory":false,"label":"v1","packageHash":"XXXXXXXXXXX","packageSize":7092826,"failedInstall":1} (vendor-es2015.js, line 86501)
[Log] [CodePush] An update is available, but it is being ignored due to have been previously rolled back. (vendor-es2015.js, line 86501)

Screenshot of device filesystem at this point:

image

Additional Information

  • cordova-plugin-code-push version: Latest version from github #capacitor branch.

(The more info the faster we will be able to address it!)

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.