forked from redpandatronicsuk/react-native-check-app-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-installed-checker.js
48 lines (40 loc) · 1.32 KB
/
app-installed-checker.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
46
47
48
import { Linking, Platform } from 'react-native';
import { APP_LIST } from './app-list';
import CheckPackageInstallation from './android';
class AppInstalledChecker {
static getAppList() {
return Object.keys(APP_LIST);
}
static checkPackageName(packagename) {
return new Promise((resolve, reject) => {
CheckPackageInstallation.isPackageInstalled(packagename, (isInstalled) => {
resolve(isInstalled);
});
});
}
static checkURLScheme(proto, query) {
return new Promise((resolve, reject) => {
Linking
.canOpenURL(proto + '://' + query || '')
.then((isInstalled) => {
resolve(isInstalled);
})
.catch((err) => {
reject(err);
});
});
}
static isAppInstalled(key) {
return Platform.select({
ios: () => { return this.isAppInstalledIOS(key); },
android: () => { return this.isAppInstalledAndroid(key); }
})();
}
static isAppInstalledAndroid(key) {
return this.checkPackageName(key);
}
static isAppInstalledIOS(key) {
return this.checkURLScheme(APP_LIST[key].urlScheme, APP_LIST[key].urlParams);
}
}
export default AppInstalledChecker;