Skip to content

Repository files navigation

react-native-version-check

npm versionnpm downloadsBuild StatusDevDependencies StatusKnown Vulnerabilities

A version checker for react-native applications. This library gets the latest app version by parsing google play store, apple app store's app information or custom url. Parsing code is referenced from here

Looking for maintainers!

I have almost zero experience in ios development, and I am no longer working on mobile app development(doing backend and devops works mainly and some web frontend). It makes it hard to maintain this library actively. Hope to have someone to help maintaining react-native-version-check!

expo

react-native-version-check supports expo! with react-native-version-check-expo

  • usage
// importimportVersionCheckfrom'react-native-version-check-expo'VersionCheck.getCountry().then(country=>console.log(country))

Getting started

  • npm
$ npm install react-native-version-check
  • yarn
$ yarn add react-native-version-check

Example

$ git clone https://github.com/kimxogus/react-native-version-check.git
$ cd react-native-version-check/example
$ yarn # or npm install
$ react-native run-android # or react-native run-ios

Automatic Installation

$ react-native link react-native-version-check

Manual Installation

- iOS - Link Manually

  • Add .xcodeproj file as library to XCode project.

    1. In project navigator, right click Libraries
    2. Select Add Files to [PROJECT_NAME]
    3. Add the node_modules/react-native-version-check/ios/RNVersionCheck.xcodeproj file
  • Add the libRNVersionCheck.a from the RNVersionCheck project to your project's Build Phases > Link Binary With Libraries

iOS - CocoaPods Package Manager

  • Add to your Podfile (assuming it's in ios/Podfile):
    pod'react-native-version-check',:path=>'../node_modules/react-native-version-check'
  • Reinstall pod with cd ios && pod install && cd ..

- Android

  • Append the following lines to android/settings.gradle:
...
include ':react-native-version-check'
project(':react-native-version-check').projectDir =newFile(rootProject.projectDir, '../node_modules/react-native-version-check/android')
  • Insert the following lines inside the dependencies block in android/app/build.gradle:
...
dependencies {
...
compile project(':react-native-version-check')
}
  • Open up android/app/src/main/java/[...]/MainApplication.java
......
importio.xogus.reactnative.versioncheck.RNVersionCheckPackage; // <--- HERE
......
@OverrideprotectedList<ReactPackage> getPackages() {
......
newRNVersionCheckPackage() // <------ HERE
......
}

Usage

import{Linking}from'react-native';importVersionCheckfrom'react-native-version-check';VersionCheck.getCountry().then(country=>console.log(country));// KRconsole.log(VersionCheck.getPackageName());// com.reactnative.appconsole.log(VersionCheck.getCurrentBuildNumber());// 10console.log(VersionCheck.getCurrentVersion());// 0.1.1VersionCheck.getLatestVersion().then(latestVersion=>{console.log(latestVersion);// 0.1.2});VersionCheck.getLatestVersion({provider: 'appStore'// for iOS}).then(latestVersion=>{console.log(latestVersion);// 0.1.2});VersionCheck.getLatestVersion({provider: 'playStore'// for Android}).then(latestVersion=>{console.log(latestVersion);// 0.1.2});VersionCheck.getLatestVersion()// Automatically choose profer provider using `Platform.select` by device platform..then(latestVersion=>{console.log(latestVersion);// 0.1.2});VersionCheck.getLatestVersion({forceUpdate: true,provider: ()=>fetch('http://your.own/api').then(r=>r.json()).then(({version})=>version),// You can get latest version from your own api.}).then(latestVersion=>{console.log(latestVersion);});VersionCheck.needUpdate().then(asyncres=>{console.log(res.isNeeded);// trueif(res.isNeeded){Linking.openURL(res.storeUrl);// open store if update is needed.}});VersionCheck.needUpdate({depth: 2}).then(res=>{console.log(res.isNeeded);// false; because first two fields of current and the latest versions are the same as "0.1".});VersionCheck.needUpdate({currentVersion: "1.0",latestVersion: "2.0"}).then(res=>{console.log(res.isNeeded);// true});VersionCheck.needUpdate({depth: 1,currentVersion: "2.1",latestVersion: "2.0",}).then(res=>{console.log(res.isNeeded);// false});

Methods

  • #getCountry()(Promise<country: String>) - Returns device's country code of 2 characters.

  • #getPackageName()(packageName: String) - Returns package name of app.

  • #getCurrentBuildNumber()(buildNumber: Number) - Returns current app build number.

  • #getStoreUrl([option: Object])(Promise<storeUrl: String>) - Returns url of Play Market or App Store of app.

  • #getAppStoreUrl([option: Object])(Promise<storeUrl: String>) - Returns url of App Store of app.

    • Option

      FieldTypeDefault
      appIDstringApp ID
      ignoreErrorsbooleantrue
  • #getPlayStoreUrl([option: Object])(Promise<storeUrl: String>) - Returns url of Play Store of app.

    • Option

      FieldTypeDefault
      packageNamestringPackage Name
      ignoreErrorsbooleantrue
  • #getCurrentVersion()(currentVersion: String) - Returns current app version.

  • #getLatestVersion([option: Object])(Promise<latestVersion: String>) - Returns the latest app version parsed from url. Returns null when parsing error occurs.

    • Option

      FieldTypeDefault
      forceUpdatebooleanfalse
      providerstring or functionprovider name or function that returns promise or value of the latest version
      fetchOptionsobjectisomorphic-fetch options (https://github.github.io/fetch/)
      ignoreErrorsbooleantrue
  • #needUpdate([option: Object])(Promise<result: Object>) - Returns an object contains with boolean value whether update needed, current version and latest version. Current and the latest app versions are first split by delimiter, and check each split numbers into depth.

    • Option

      FieldTypeDefault
      currentVersionstringapp's current version from getCurrentVersion()
      latestVersionstringapp's latest version from getLatestVersion()
      depthnumberInfinity
      forceUpdatebooleanfalse
      providerstring or functionprovider name or function that returns promise or value of the latest version
      fetchOptionsobjectisomorphic-fetch options (https://github.github.io/fetch/)
      ignoreErrorsbooleantrue
    • Result

      FieldType
      isNeededboolean
      storeUrlstring
      currentVersionstring
      latestVersionstring

License

MIT

About

A version checker for react-native applications

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages