-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathindex.js
40 lines (36 loc) · 1.11 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
import { Linking, Platform } from 'react-native';
export const maybeOpenURL = async (
url,
{ appName, appStoreId, appStoreLocale, playStoreId }
) => {
Linking.openURL(url).catch(err => {
if (err.code === 'EUNSPECIFIED') {
if (Platform.OS === 'ios') {
// check if appStoreLocale is set
const locale = typeof appStoreLocale === 'undefined'
? 'us'
: appStoreLocale;
Linking.openURL(`https://apps.apple.com/${locale}/app/${appName}/id${appStoreId}`);
} else {
Linking.openURL(
`https://play.google.com/store/apps/details?id=${playStoreId}`
);
}
} else {
throw new Error(`Could not open ${appName}. ${err.toString()}`);
}
});
};
export const openInStore = async ({ appName, appStoreId, appStoreLocale = 'us', playStoreId }) => {
if (Platform.OS === 'ios') {
Linking.openURL(`https://apps.apple.com/${appStoreLocale}/app/${appName}/id${appStoreId}`);
} else {
Linking.openURL(
`https://play.google.com/store/apps/details?id=${playStoreId}`
);
}
};
export default {
maybeOpenURL,
openInStore,
};