Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kimxogus/react-native-version-check
A version checker for react-native applications
https://github.com/kimxogus/react-native-version-check
react-native version version-check
Last synced: 5 days ago
JSON representation
A version checker for react-native applications
- Host: GitHub
- URL: https://github.com/kimxogus/react-native-version-check
- Owner: kimxogus
- License: mit
- Created: 2016-10-15T08:35:35.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-13T18:09:49.000Z (11 months ago)
- Last Synced: 2024-04-14T12:50:33.111Z (8 months ago)
- Topics: react-native, version, version-check
- Language: Java
- Homepage:
- Size: 15 MB
- Stars: 681
- Watchers: 17
- Forks: 162
- Open Issues: 56
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-version-check
[![npm version][npm-image]][npm-url]
[![npm downloads][downloads-image]][downloads-url]
[![Build Status][ci-image]][ci-url]
[![DevDependencies Status][dev-dependencies-image]][dev-dependencies-url]
[![Known Vulnerabilities][vulnerabilities-image]][vulnerabilities-url]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](http://itmir.tistory.com/524)### 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](https://expo.io)! with [react-native-version-check-expo](https://www.npmjs.com/package/react-native-version-check-expo)
- usage
```js
// import
import VersionCheck from 'react-native-version-check-expo'VersionCheck.getCountry().then(country => console.log(country))
```## Getting started
- npm
```bash
$ npm install react-native-version-check
```
- yarn
```bash
$ yarn add react-native-version-check
```### Example
```bash
$ 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
```bash
$ 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`):
```ruby
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`:
```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`:
```gradle
...
dependencies {
...
compile project(':react-native-version-check')
}
```
* Open up `android/app/src/main/java/[...]/MainApplication.java`
```java
......
import io.xogus.reactnative.versioncheck.RNVersionCheckPackage; // <--- HERE......
@Override
protected List getPackages() {
......
new RNVersionCheckPackage() // <------ HERE
......
}
```## Usage
```javascript
import { Linking } from 'react-native';
import VersionCheck from 'react-native-version-check';VersionCheck.getCountry()
.then(country => console.log(country)); // KR
console.log(VersionCheck.getPackageName()); // com.reactnative.app
console.log(VersionCheck.getCurrentBuildNumber()); // 10
console.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(async res => {
console.log(res.isNeeded); // true
if (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)_ - 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)_ - Returns url of Play Market or App Store of app.
- #**`getAppStoreUrl([option: Object])`** _(Promise)_ - Returns url of App Store of app.
- OptionField | Type | Default
--- | --- | ---
appID | _string_ | App ID
ignoreErrors | _boolean_ | true
- #**`getPlayStoreUrl([option: Object])`** _(Promise)_ - Returns url of Play Store of app.
- OptionField | Type | Default
--- | --- | ---
packageName | _string_ | Package Name
ignoreErrors | _boolean_ | true- #**`getCurrentVersion()`** _(currentVersion: String)_ - Returns current app version.
- #**`getLatestVersion([option: Object])`** _(Promise)_ - Returns the latest app version parsed from url. Returns `null` when parsing error occurs.
- OptionField | 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/)
ignoreErrors | _boolean_ | true- #**`needUpdate([option: Object])`** _(Promise)_ - 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.
- OptionField | Type | Default
--- | --- | ---
currentVersion | _string_ | app's current version from [getCurrentVersion()](#getCurrentVersion)
latestVersion | _string_ | app's latest version from [getLatestVersion()](#getLatestVersion)
depth | _number_ | ```Infinity```
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/)
ignoreErrors | _boolean_ | true- Result
Field | Type
--- | ---
isNeeded | _boolean_
storeUrl | _string_
currentVersion | _string_
latestVersion | _string_## License
MIT[npm-image]: https://img.shields.io/npm/v/react-native-version-check.svg
[npm-url]: https://npmjs.org/package/react-native-version-check
[downloads-image]: https://img.shields.io/npm/dm/react-native-version-check.svg
[downloads-url]: https://npmjs.org/package/react-native-version-check
[ci-image]: https://circleci.com/gh/kimxogus/react-native-version-check.svg?style=svg
[ci-url]: https://circleci.com/gh/kimxogus/react-native-version-check
[dev-dependencies-image]: https://david-dm.org/kimxogus/react-native-version-check/dev-status.svg
[dev-dependencies-url]: https://david-dm.org/kimxogus/react-native-version-check?type=dev
[vulnerabilities-image]: https://snyk.io/test/github/kimxogus/react-native-version-check/badge.svg
[vulnerabilities-url]: https://snyk.io/test/github/kimxogus/react-native-version-check