Giter Site home page Giter Site logo

titozzz / react-native-version-check Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kimxogus/react-native-version-check

0.0 3.0 0.0 9.74 MB

A version checker for react-native applications

License: MIT License

JavaScript 11.93% Java 30.28% Python 12.78% Objective-C 40.66% Ruby 4.35%

react-native-version-check's Introduction

react-native-version-check

npm version npm downloads Build Status DevDependencies Status Known 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

expo

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

  • usage
// import
import VersionCheck from 'react-native-version-check-expo'

VersionCheck.getCountry() // this will return promise!!

VersionCheck.getCountryAsync().then(country => console.log(country)) // or use this!

Getting started

To supress iOS warnings in RN>=0.51, use react-native-version-check@>=2.2.0. #18

  • npm
$ npm install react-native-version-check --save
  • 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

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 = new File(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
......
import io.xogus.reactnative.versioncheck.RNVersionCheckPackage;  // <--- HERE

......

@Override
protected List<ReactPackage> getPackages() {
   ......
   new RNVersionCheckPackage()            // <------ HERE
   ......
}

Usage

import { Linking } from 'react-native';
import VersionCheck from 'react-native-version-check';

// START: iOS Only

VersionCheck.setAppID(APP_ID);                    // Your App ID for App Store URL
VersionCheck.setAppName(APP_NAME);                // Your App Name for App Store URL

// Your app's id, name and country info will be use for App Store URL like
// https://itunes.apple.com/{COUNTRY}/app/{APP_NAME}/id{APP_ID}

// END: iOS Only

VersionCheck.getCountryAsync()
  .then(country => console.log(country));          // KR
console.log(VersionCheck.getPackageName());        // com.reactnative.app
console.log(VersionCheck.getCurrentBuildNumber()); // 10
console.log(VersionCheck.getCurrentVersion());     // 0.1.1

VersionCheck.getLatestVersion()
  .then(latestVersion => {
    console.log(latestVersion);    // 0.1.2
  });

VersionCheck.getLatestVersion({
    provider: 'store'
  })
  .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.
  fetchOptions: {
    method: "GET"
  }
}).then(latestVersion =>{
  console.log(latestVersion);
});

VersionCheck.needUpdate()
  .then(async res => {
    console.log(res.isNeeded);    // true
    if (res.isNeeded) {
      Linking.openURL(await VersionCheck.getStoreUrl());  // 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({
  currentVersion: "1.1",
  latestVersion: "2.0",
  semantic: true
}).then(res => {
  console.log(res.isNeeded);  // false
});

Methods

  • #setAppID(appId: Number) () - Sets app id of application for App Store Url. [Required only for iOS Apps]

  • #setAppName(appName: String) () - Sets app name of application for App Store Url. [Required only for iOS Apps]

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

  • #getCountryAsync() (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]) (storeUrl: String) - Returns url of Play Market or App Store of app.

    • Option

      Field Type Default
      appID string App ID which was set by setAppID()
      appName string App Name which was set by setAppName()
  • #getStoreUrlAsync([option: Object]) (Promise<storeUrl: String>) - Returns url of Play Market or App Store of app.

    • Option

      Field Type Default
      appID string App ID which was set by setAppID()
      appName string App Name which was set by setAppName()
  • #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

      Field Type Default
      forceUpdate boolean false
      provider string or function provider name or function that returns promise or value of the latest version
      fetchOptions object isomorphic-fetch options (https://github.github.io/fetch/)
  • #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

      Field Type Default
      currentVersion string app's current version from getCurrentVersion()
      latestVersion string app's latest version from getLatestVersion()
      depth number Infinity
      delimiter string "."
      semantic boolean false
      forceUpdate boolean false
      provider string or function provider name or function that returns promise or value of the latest version
      fetchOptions object isomorphic-fetch options (https://github.github.io/fetch/)
    • Result

      Field Type
      isNeeded boolean
      currentVersion string
      latestVersion string

License

MIT

react-native-version-check's People

Contributors

kimxogus avatar andriichernenko avatar behzad888 avatar macintoshhelper avatar

Watchers

James Cloos avatar Thibault Malbranche avatar  avatar

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.