-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
45 lines (40 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Platform, NativeModules } from "react-native";
import { lookupVersion } from "./src/utils";
import { versionCompare } from "./src/versions";
const DEFAULT_COUNTRY = "us";
export const checkVersion = async(options = {}) => {
// Get options object
const platform = options.platform || Platform.OS;
const country = options.country || DEFAULT_COUNTRY;
const bundleId = options.bundleId || (NativeModules.RNDeviceInfo
? NativeModules.RNDeviceInfo.bundleId
: null);
const currentVersion = options.currentVersion || (NativeModules.RNDeviceInfo
? NativeModules.RNDeviceInfo.appVersion
: "");
// Check if we have retrieved a bundle ID
if (!bundleId && !("RNDeviceInfo" in NativeModules)) {
throw Error(
"[react-native-check-version] Missing react-native-device-info dependency, " +
"please manually specify a bundleId in the options object."
);
}
try {
const data = await lookupVersion(platform, bundleId, country);
const version = versionCompare(currentVersion, data.version);
return { platform, bundleId, ...data, ...version };
} catch (e) {
// On error - return default object
return {
platform,
bundleId,
version: null,
needsUpdate: false,
notes: "",
url: null,
lastChecked: (new Date()).toISOString(),
country,
error: e
};
}
};