diff --git a/README.md b/README.md index a7eda5b..6ec86b4 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@

-Easily deep link to other apps in React Native. If the app isn't installed on the user's phone, open the App Store or Play Store link instead. +Easily deep link to other apps in React Native. If the app isn't installed on the user's phone, open the App Store, Play Store or AppGallery link instead.

--- @@ -35,14 +35,14 @@ Easily deep link ```javascript import AppLink from 'react-native-app-link'; -AppLink.maybeOpenURL(url, { appName, appStoreId, appStoreLocale, playStoreId }).then(() => { +AppLink.maybeOpenURL(url, { appName, appStoreId, appStoreLocale, playStoreId, appGalleryId }).then(() => { // do stuff }) .catch((err) => { // handle error }); -AppLink.openInStore({ appName, appStoreId, appStoreLocale, playStoreId }).then(() => { +AppLink.openInStore({ appName, appStoreId, appStoreLocale, playStoreId, appGalleryId }).then(() => { // do stuff }) .catch((err) => { @@ -52,7 +52,7 @@ AppLink.openInStore({ appName, appStoreId, appStoreLocale, playStoreId }).then(( ## API: -### `maybeOpenURL(url, config) -> Promise` Opens link if app is present. If not, it opens an app store to prompt the user to download it. +### `maybeOpenURL(url, config) -> Promise` Opens link if app is present. If not, it opens an app store to prompt the user to download it. `url`: (String) a url in the specified app's [deep linking](https://en.wikipedia.org/wiki/Mobile_deep_linking) format that points to the content you want to open. @@ -62,13 +62,15 @@ AppLink.openInStore({ appName, appStoreId, appStoreLocale, playStoreId }).then(( `config.appStoreId`: (String) the app's ID on the App Store (iOS). Example: `{ appStoreId: '529379082' }` -`config.appStoreLocale`: (String) the App Store's locale (iOS). Defaults to the USA App Store. Example: `{ appStoreId: 'us' }` +`config.appStoreLocale`: (String) the App Store's locale (iOS). Defaults to the USA App Store. Example: `{ appStoreLocale: 'us' }` `config.playStoreId`: (String) the app's package identifier on the Play Store (Android). Example: `{ playStoreId: 'me.lyft.android' }` +`config.appGalleryId`: (String) the app's ID on the AppGallery (Android). Example: `{ appGalleryId: '100170981' }` + --- -### `openInStore(config) -> Promise` Opens an app store to the listing requested. +### `openInStore(config) -> Promise` Opens an app store to the listing requested. `config`: (Object) a config for generate store urls. @@ -80,4 +82,6 @@ AppLink.openInStore({ appName, appStoreId, appStoreLocale, playStoreId }).then(( `config.playStoreId`: (String) the app's package identifier on the Play Store (Android). Example: `{ playStoreId: 'me.lyft.android' }` +`config.appGalleryId`: (String) the app's ID on the AppGallery (Android). Example: `{ appGalleryId: '100170981' }` + > If there are any issues file an issue above and don't hesitate to spin up a PR and contribute! diff --git a/index.js b/index.js index fbaae91..bf4a902 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ import { Linking, Platform } from 'react-native'; export const maybeOpenURL = async ( url, - { appName, appStoreId, appStoreLocale, playStoreId } + { appName, appStoreId, appStoreLocale, playStoreId, appGalleryId = null } ) => { Linking.openURL(url).catch(err => { if (err.code === 'EUNSPECIFIED') { @@ -14,9 +14,23 @@ export const maybeOpenURL = async ( Linking.openURL(`https://itunes.apple.com/${locale}/app/${appName}/id${appStoreId}`); } else { - Linking.openURL( - `https://play.google.com/store/apps/details?id=${playStoreId}` - ); + if(appGalleryId != null) { + Linking.openURL( + `hiapplink://com.huawei.appmarket?appId=C${appGalleryId}` + ).catch(err => { + console.log(err) + if(err.code == 'EUNSPECIFIED') { + Linking.openURL( + `https://play.google.com/store/apps/details?id=${playStoreId}` + ); + } + }) + } + else { + Linking.openURL( + `https://play.google.com/store/apps/details?id=${playStoreId}` + ); + } } } else { throw new Error(`Could not open ${appName}. ${err.toString()}`); @@ -24,13 +38,27 @@ export const maybeOpenURL = async ( }); }; -export const openInStore = async ({ appName, appStoreId, appStoreLocale = 'us', playStoreId }) => { +export const openInStore = async ({ appName, appStoreId, appStoreLocale = 'us', playStoreId, appGalleryId = null }) => { if (Platform.OS === 'ios') { Linking.openURL(`https://itunes.apple.com/${appStoreLocale}/app/${appName}/id${appStoreId}`); } else { - Linking.openURL( - `https://play.google.com/store/apps/details?id=${playStoreId}` - ); + if(appGalleryId != null) { + Linking.openURL( + `hiapplink://com.huawei.appmarket?appId=C${appGalleryId}` + ).catch(err => { + console.log(err) + if(err.code == 'EUNSPECIFIED') { + Linking.openURL( + `https://play.google.com/store/apps/details?id=${playStoreId}` + ); + } + }) + } + else { + Linking.openURL( + `https://play.google.com/store/apps/details?id=${playStoreId}` + ); + } } };