react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

CodePush.getCurrentPackage() is returning undefined

Open HannanShaik opened this issue 9 years ago • 4 comments

Since Codepush does not have facility to do rollout to specific set of users. I have built my own. In this, I check the current codepush version and then compare to the one i have pushed. If there's any delta I call CodePush.sync()

However, CodePush.getCurrentPackage() is returning me undefined.

return CodePush.getCurrentPackage().then((packageInfo) => {
                console.log(packageInfo); //this is giving undefined.
                //compare this with latest version from my service and then call CodePush.sync();

  • react-native-code-push version:^2.0.3-beta
  • react-native version:0.44.0

HannanShaik avatar Aug 07 '17 12:08 HannanShaik

Got the answer from docs. https://microsoft.github.io/code-push/docs/react-native.html

null if the app is currently running the JS bundle 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 JS binary in the binary.

In my case, Scenario 1 has happened.

HannanShaik avatar Aug 08 '17 06:08 HannanShaik

Hi @HannanShaik, please note that this method is considered deprecated as of v1.10.3-beta of the CodePush module.
Could you please try running getUpdateMetadata method instead with codePush.UpdateState.PENDING updateState parameter. To get currently installed update you can run this method with codePush.UpdateState.RUNNING parameter but note that it can return null in case the end-user hasn't installed any CodePush updates yet or app isn't currently running a CodePush update.

Please let us know if any questions.

max-mironov avatar Aug 08 '17 06:08 max-mironov

Yes @max-mironov I will use getUpdateMetadata.

In case of a fresh release to app store, i will get null right? At this point should I call CodePush.sync() but there is no bundle that I have pushed to codepush yet.

HannanShaik avatar Aug 08 '17 06:08 HannanShaik

Yep, you'll get null if you have fresh install, also I think may be it would be better to call checkForUpdate method in your case to see if update is available and if it should be downloaded for specific user (and it will depend upon remotePackage instance that can be returned by this method).

max-mironov avatar Aug 08 '17 06:08 max-mironov