Skip to content

feat(updated-time): added a new method getLatestUpdatedTime #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 123 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,38 @@ This library gets the latest app version by parsing google play store, apple app
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'
import VersionCheck from 'react-native-version-check-expo';

VersionCheck.getCountry().then(country => console.log(country))
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
```

- 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
Expand All @@ -42,43 +51,53 @@ $ 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.

- 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
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
- 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`):

- 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 ..`
- Reinstall pod with `cd ios && pod install && cd ..`

#### - Android

* Append the following lines to `android/settings.gradle`:
- 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`:

- 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`

- Open up `android/app/src/main/java/[...]/MainApplication.java`

```java
......
import io.xogus.reactnative.versioncheck.RNVersionCheckPackage; // <--- HERE
Expand All @@ -94,79 +113,80 @@ protected List<ReactPackage> getPackages() {
```

## 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
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.1
console.log(VersionCheck.getCurrentVersion()); // 0.1.1

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

VersionCheck.getLatestVersion({
provider: 'appStore' // for iOS
})
.then(latestVersion => {
console.log(latestVersion); // 0.1.2
});
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
});
provider: 'playStore', // for Android
}).then(latestVersion => {
console.log(latestVersion); // 0.1.2
});

VersionCheck.getLatestVersion() // Automatically choose profer provider using `Platform.select` by device platform.
VersionCheck.getLatestVersion() // Automatically choose profer provider using `Platform.select` by device platform.
.then(latestVersion => {
console.log(latestVersion); // 0.1.2
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 =>{
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.getLatestUpdatedTime() // You can check when the app is last updated.
.then(updatedTime => {
console.log(updateTime); // 2022-05-30T16:00:00.000Z (Date)
});

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
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"
currentVersion: '1.0',
latestVersion: '2.0',
}).then(res => {
console.log(res.isNeeded); // true
console.log(res.isNeeded); // true
});

VersionCheck.needUpdate({
depth: 1,
currentVersion: "2.1",
latestVersion: "2.0",
currentVersion: '2.1',
latestVersion: '2.0',
}).then(res => {
console.log(res.isNeeded); // false
console.log(res.isNeeded); // false
});

```

## Methods
Expand All @@ -176,58 +196,71 @@ VersionCheck.needUpdate({
- <a name="getCurrentBuildNumber" href="#getCurrentBuildNumber">#</a>**`getCurrentBuildNumber()`** _(buildNumber: Number)_ - Returns current app build number.
- <a name="getStoreUrl" href="#getStoreUrl">#</a>**`getStoreUrl([option: Object])`** _(Promise<storeUrl: String>)_ - Returns url of Play Market or App Store of app.
- <a name="getAppStoreUrl" href="#getAppStoreUrl">#</a>**`getAppStoreUrl([option: Object])`** _(Promise<storeUrl: String>)_ - Returns url of App Store of app.

- Option

Field | Type | Default
--- | --- | ---
appID | _string_ | App ID
ignoreErrors | _boolean_ | true
| Field | Type | Default |
| ------------ | --------- | ------- |
| appID | _string_ | App ID |
| ignoreErrors | _boolean_ | true |

- <a name="getPlayStoreUrl" href="#getPlayStoreUrl">#</a>**`getPlayStoreUrl([option: Object])`** _(Promise<storeUrl: String>)_ - Returns url of Play Store of app.

- Option

Field | Type | Default
--- | --- | ---
packageName | _string_ | Package Name
ignoreErrors | _boolean_ | true
| Field | Type | Default |
| ------------ | --------- | ------------ |
| packageName | _string_ | Package Name |
| ignoreErrors | _boolean_ | true |

- <a name="getCurrentVersion" href="#getCurrentVersion">#</a>**`getCurrentVersion()`** _(currentVersion: String)_ - Returns current app version.
- <a name="getLatestVersion" href="#getLatestVersion">#</a>**`getLatestVersion([option: Object])`** _(Promise<latestVersion: String>)_ - Returns the latest app version parsed from url. Returns `null` when parsing error occurs.
- <a name="getLatestVersion" href="#getLatestVersion">#</a>**`getLatestVersion([option: Object])`** _(Promise<latestVersion: String>)_ - Returns the latest app version parsed from url.

- 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/)
ignoreErrors | _boolean_ | true
| 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/) |
| ignoreErrors | _boolean_ | true |

* <a name="getLatestUpdatedTime" href="#getLatestUpdatedTime">#</a>**`getLatestUpdatedTime([option: Object])`** _(Promise<latestUpdatedTime: Date>)_ - Returns the latest app updated time parsed from url.

- <a name="needUpdate" href="#needUpdate">#</a>**`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()](#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
| Field | Type | Default |
| ------------ | ---------------------- | ----------------------------------------------------------------------------- |
| 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
* <a name="needUpdate" href="#needUpdate">#</a>**`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
--- | ---
isNeeded | _boolean_
storeUrl | _string_
currentVersion | _string_
latestVersion | _string_
| Field | 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

MIT

[npm-image]: https://img.shields.io/npm/v/react-native-version-check.svg
[npm-url]: https://npmjs.org/package/react-native-version-check
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-version-check/builder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import { getLatestVersion } from './src/getLatestVersion';
import { getLatestUpdatedTime } from './src/getLatestUpdatedTime';
import needUpdate from './src/needUpdate';
import { setVersionInfo, type IVersionInfo } from './src/versionInfo';
import getStoreUrl, {
Expand All @@ -12,6 +13,7 @@ export interface ReactNativeVersionCheck extends IVersionInfo {
getAppStoreUrl: typeof getAppStoreUrl;
getPlayStoreUrl: typeof getPlayStoreUrl;
getLatestVersion: typeof getLatestVersion;
getLatestUpdatedTime: typeof getLatestUpdatedTime;
needUpdate: typeof needUpdate;
}

Expand All @@ -28,6 +30,7 @@ export default (VersionInfoObject: IVersionInfo): ReactNativeVersionCheck => {
getAppStoreUrl,
getPlayStoreUrl,
getLatestVersion,
getLatestUpdatedTime,

needUpdate,
};
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-version-check/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-native-version-check",
"name": "@mydidian/react-native-version-check",
"version": "3.4.7",
"description": "A version checker for react-native applications",
"main": "index.js",
Expand Down Expand Up @@ -32,6 +32,7 @@
"lodash.isfunction": "^3.0.9",
"lodash.isnil": "^4.0.0",
"lodash.pick": "^4.4.0",
"luxon": "^3.3.0",
"semver": "^6.1.1"
},
"devDependencies": {
Expand Down
Loading