Code Monkey home page Code Monkey logo

react-native-check-version's Introduction

React Native Check Version

NPM GitHub license


An easy way to check if there's an update available for the current app in the App Store or Google Play.

Note that you need react-native-device-info to be installed for this library to function as expected, or you need to manually supply the bundleId and currentVersion values in the options object.

Installation

yarn add react-native-check-version react-native-device-info

Basic usage

Use the checkVersion method to get information:

import { checkVersion } from "react-native-check-version";

const version = await checkVersion();
console.log("Got version info:", version);

if (version.needsUpdate) {
   console.log(`App has a ${version.updateType} update pending.`);
}

API

Function usage

checkVersion() accepts an optional options object, which may contain the following keys:

  • string platform: platform to check for, defaults to React Native's Platform.OS
  • string country: App Store specific country, defaults to us
  • string bundleId: bundle identifier to check, defaults to the value retrieved using react-native-device-info
  • string currentVersion: version to check against, defaults to the currently installed version

Response object

checkVersion() returns a Promise, which when resolved will return an object with the following properties:

  • string version: latest version number of the app
  • string released: (iOS only) ISO 8601 release date of that version
  • string url: download URL for the latest version
  • string notes: (iOS only) release notes of latest version
  • boolean needsUpdate: whether the latest version number is higher than the currently installed one
  • string updateType: major, minor or patch, based on how big the difference is between the currently installed version and the available version

Changelog

  • v1.1.0: Use built-in fetch rather than Axios library.
  • v1.0.18: Update headers for Google Play HTTP request.
  • v1.0.14: Updated Android logic to use new Google Play endpoints.
  • v1.0.13: Added a try-catch within the main checkVersion function to prevent error responses from the HTTP requests to throw errors.
  • v1.0.12: Replaced the custom backend used previously by doing calls directly within the app. Please note Google Play has updated their web pages, making older versions not functional.

Authors

This library is developed by Flexible Agency, a creative app development agency.




Get professional support for this package →
Custom consulting sessions available for implementation support or feature development.

react-native-check-version's People

Contributors

arlandantas avatar dawidzawadzki avatar filipengberg avatar gantelo avatar jensdev avatar m4tdev avatar sergiodiez avatar slavikdenis avatar tschoffelen avatar zanechua 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

react-native-check-version's Issues

problem severity 1

Updated this.appVersion = await checkVersion(); fail.

Something was used in this method that stopped a super critical application.

The app is crashing

Help me

checkVersion is not working in latest version 1.0.20

Check version is returning “needsUpdate”: false, “url”: null, and “version”: null.
On further investigation, I found that the regex match is not working with the new google play UI changes.
Please update the library accordingly.

Error: #<WeakSet> could not be cloned

  • node /Users/flavio/Documents/Lavori/boxshop/boxshopW/node_modules/react-native/cli.js bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/flavio/Documents/Lavori/boxshop/boxshopW/ios/DerivedData/svogly/Build/Products/Release-iphoneos/main.jsbundle --assets-dest /Users/flavio/Documents/Lavori/boxshop/boxshopW/ios/DerivedData/svogly/Build/Products/Release-iphoneos/Svogly.app
    warning: the transform cache was reset.
    Welcome to Metro!
    Fast - Scalable - Integrated

error node_modules/react-native-check-version/index.js: # could not be cloned.
Error: # could not be cloned.
at Object.serialize (v8.js:283:7)
at _default (/Users/flavio/Documents/Lavori/boxshop/boxshopW/node_modules/@babel/core/lib/transformation/util/clone-deep.js:22:34)
at normalizeFile (/Users/flavio/Documents/Lavori/boxshop/boxshopW/node_modules/@babel/core/lib/transformation/normalize-file.js:79:36)
at normalizeFile.next ()
at run (/Users/flavio/Documents/Lavori/boxshop/boxshopW/node_modules/@babel/core/lib/transformation/index.js:29:50)
at run.next ()
at /Users/flavio/Documents/Lavori/boxshop/boxshopW/node_modules/@babel/core/lib/transform-ast.js:26:41
at Generator.next ()
at evaluateSync (/Users/flavio/Documents/Lavori/boxshop/boxshopW/node_modules/@babel/core/node_modules/gensync/index.js:251:28)
info Run CLI with --verbose flag for more details.
Command /bin/sh failed with exit code 1

"Not a valid semver version: Varies with device"

My application on the device is with version 1.0.3 exactly the same as the store, but needsUpdate always returns true.

I tried to change the device version to 1.0.4 in an attempt to solve the problem, but needsUpdate still returns true.

image

image

help IOS version check

Currently how can i check my current app version? when i am trying through DeviceInfo.getVersion() its retrieve the build version.

[Question] Internal version number

Hello,
Does the check also work for internal version numbers such as Android versionCode and iOS build number ?
If I release a 2.0.0 version with versionCode 100, can I know if there is a update of version 2.0.0 with versionCode 101 ?

The check version method issue

this.appVersion = await checkVersion();
The app crashes when I called this method, I think it is due to your updates 3 hours ago.

app version doesn't update

I updated my appstore app with a new version (1.1.6)

call the api with the current version 1.1.5
https://check-version.flexible.agency/ios/com.pennstate.wwyc/1.1.5?country=us

always return with version 1.1.5

Looking through the server code "utils.js"

const axios = require("axios");

const cache = {}

const lookupVersion = async(platform, bundleId, country = 'us') => {
  const key = `${platform}.${bundleId}`;
  let res = cache[key];
  if (res) {
    return res;
  }

Apparently, it is always returning the result with platform and bundleId. Is this expected, that the server will only register the app info once?

Safari cannot open the page because the address is invalid

I'm getting the following error when trying to open version.url with
Linking.openURL(version.url)

Safari cannot open the page because the address is invalid

My version object looks like this:
{"bundleId": "com.dahlsjoo.shinner", "country": "us", "lastChecked": "2021-07-16T00:05:22.581Z", "needsUpdate": false, "notes": "Bug fixes", "platform": "ios", "released": "2021-07-01T18:19:45Z", "updateType": null, "url": "https://apps.apple.com/us/app/shinner-skate-spots-videos/id1476836516?uo=4", "version": "1.2.4"}

Android failing to get current play store version

I am getting the following return/error:

{
  "bundleId": "xxxxx",
  "country": "us",
  "error": [TypeError: null is not an object (evaluating 'res.data.match(/\[\[\[['"]((\d+\.)+\d+)['"]\]\],/)[1]')],
  "lastChecked": "2022-10-11T21:09:44.941Z",
  "needsUpdate": false,
  "notes": "",
  "platform": "android",
  "url": null,
  "version": null,
}

And it seems that the Play Store HTML structure has changed.
The following PR is my suggestion to fix it:
#45

[Android] version is null

Hi, On Android 10 I am getting version null and error "Error: Request failed with status code 403". Adding 'sec-fetch-site': 'same-origin' to headers solves the problem. Could you check it?

getting error on Android

"react-native-check-version": "^1.1.1",
"react-native": "0.66.5",
{ platform: 'android',
bundleId: 'com.tntmobile',
version: null,
needsUpdate: false,
notes: '',
url: null,
lastChecked: '2023-05-28T12:37:39.902Z',
country: 'fr',
error: [TypeError: Cannot convert null value to object] }

in node modules here is the issue
const text = await res.text();
const version = text.match(/[[['"['"]]],/)[1];
getting null while applying the regex

cant get version result in Android

import { checkVersion } from "react-native-check-version";

const version = await checkVersion();
console.log("Got version info:", version);

if (version.needsUpdate) {
   console.log(`App has a ${version.updateType} update pending.`);
}

RESULT:
Got version info: {"bundleId": null, "country": "us", "error": [Error: App with bundle ID "null" not found in Google Play.], "lastChecked": "2024-04-04T03:59:10.402Z", "needsUpdate": false, "notes": "", "platform": "android", "url": null, "version": null}

Publish 1.0.14 tag to npm

Thanks for a great library.

Can you publish 1.0.14 tag to npm? It seems like the latest tag published is 1.0.12:
image
image

Thanks a lot.

Adding error field to the TS interface

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Hi! Just proposing a minor change the to TS interface to help handle errors when the app doesn't exist

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-check-version/index.d.ts b/node_modules/react-native-check-version/index.d.ts
index 20d4295..453f93b 100644
--- a/node_modules/react-native-check-version/index.d.ts
+++ b/node_modules/react-native-check-version/index.d.ts
@@ -21,6 +21,7 @@ export interface CheckVersionResponse {
   bundleId?: string;
   lastChecked?: string;
   country?: string;
+  error?: Error;
 }
 
 declare const checkVersion: (

This issue body was partially generated by patch-package.

How does this package handle Android rollouts / internal testing?

Hi guys, this package looks pretty amazing! I'm wondering how you guys handle Android rollouts? If I use 20% rollout as a default, is it just a 1/5 chance that your server will see the updated version? And is it possible that someone who is in a region that hasn't had the app rolled out to them yet will get a message that the app is available, when in fact it isn't available for them yet?

App for this bundle ID not found

i got error: {"error": "App for this bundle ID not found."}

when i checked on appstore connect, this apps bundle id is same, why got error not found?

This is bundle id when i console log:
Screen Shot 2021-04-13 at 13 22 18

And this is bundle id that i got from apple appstore connect:
Screen Shot 2021-04-13 at 13 22 24

Missing property country on CheckVersionOptions

When using typescript the property country is missing from the CheckVersionOptions interface

checkVersion({
    country: 'us' // throw: Object literal may only specify known properties, and 'country' does not exist in type 'CheckVersionOptions'
});

Store updates reach the server late

Hi again. I pushed an update to the play store and after 2 hours the updated data still didn't reach the server. It was still showing the data from the previous version.

I wanted to use this lib to force update the app but with this issue it is impossible.

NeedsUpdate showing wrong result

const version = await checkVersion({
bundleId:'africa.xxx.xx',
currentVersion:'1.0',
});
// currentVersion 1.0.2 , picking correctly from play Store
console.log(version.needsUpdate) // false

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Be more flexible on version number parsing

The application in the store is in version 0.6

Inside package.json version 0.8 is set

It turns out that the version of the app being greater than the version that is in the store it informs that it needs updating.

update added image

Captura de Tela 2021-01-21 às 18 03 42

[Question] Have you changed anything in the backend after Google Play Store UI update?

Hi, a couple of days ago Google introduced a new design to their Google Play Store, and it broke another similar package that allows getting the currently available version from the store. Did you do any changes to the match of the "Current Version" to adjust for the design changes? If so, could you provide does changes or the whole code to get the store version? Because I would prefer to implement it on the mobile side instead of reaching to a separate backend.

Invalid time value error

Hello,

CheckVersion is returning the following error on a Samsung device today:

{"error": "Invalid time value"}

Is this due to daylight saving time change today?

Error on Android

Hi guys. Thanks for the awesome library.

I have no probs with it on iOS, however on Android i'm getting this error:

Got version info: 
error: "Invalid Version: //play.google.com/">"
error: "Invalid Version: //play.google.com/">

I tried that with debug and release versions.

Is it a bug or i just need to test it on the app download from the market?

Thanks.

Why a custom backend?

I'm just trying to better understand what is the advantage of having a web service
to help the react-native-check-version package. Thanks in advance 😄

Support for closed track releases

Hello.

Any ideas, is there would be a possibility to get latest version of an android app from google play, which is closed track (alpha) release only?

Basically, it's accessible only by people granted based on email.

So maybe if there would be a configuration option like email/password OR some google API token (no idea how these works) it could be accessed?

Thanks

Patch for Require cycle: node_modules/semver/classes/comparator.js -> node_modules/semver/classes/range.js -> node_modules/semver/classes/comparator.js

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-check-version/src/versions.js b/node_modules/react-native-check-version/src/versions.js
index e69c00f..fc83676 100644
--- a/node_modules/react-native-check-version/src/versions.js
+++ b/node_modules/react-native-check-version/src/versions.js
@@ -1,7 +1,10 @@
-import semver from "semver";
+const semverParse = require('semver/functions/parse');
+const semverCoerse = require('semver/functions/coerce');
+const semverEq = require('semver/functions/eq');
+const semverLt = require('semver/functions/lt');
 
 export const parseVersion = (version) => {
-  return semver.parse(semver.coerce(version), true);
+  return semverParse(semverCoerse(version), true);
 };
 
 export const diffLoose = (version1, version2) => {
@@ -11,7 +14,7 @@ export const diffLoose = (version1, version2) => {
 
   const v1 = parseVersion(version1);
   const v2 = parseVersion(version2);
-  if (semver.lt(v2, v1) || semver.eq(v1, v2, true)) {
+  if (semverLt(v2, v1) || semverEq(v1, v2, true)) {
     return null;
   }
 

This issue body was partially generated by patch-package.

iOS App version is not latest

My app has been placed in App Store, and http://itunes.apple.com/lookup?lang=en&bundleId=com.instpower.global&country=us is 2.0.0(is latest), but https://check-version.flexible.agency/ios/com.instpower.global/1.4.3?country=us&cn=1 still return 1.4.3

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.