Skip to content

Commit e8ded40

Browse files
Merge pull request #1 from appupgrade-dev/platform-supports
Add support for Amazon app store, Huawei AppGallery and other android market places.
2 parents 7fd3062 + 92b08a8 commit e8ded40

File tree

6 files changed

+136
-19
lines changed

6 files changed

+136
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes will be documented in this file.
44

5+
## [1.0.11] - 2023-02-27
6+
7+
* Added support for Amazon, Huawei and other marketplaces.
8+
59
## [1.0.10] - 2023-02-03
610

711
* Fix url encoding for app name.

README.md

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ This SDK communicate with App Upgrade and check the version with store version i
1414
- If app needs to be updated but not a force update, it will show a dismissable popup.
1515
- If no action is required it won't do anything.
1616

17+
App Upgrade is a cross platform solution to getting users to easily update your app.
18+
##### Stores Supported:
19+
Apple App Store | Google Play Store | Amazon App Store | Huawei AppGallery | Other Android Markets
20+
--- | --- | --- | --- | ---
21+
**** | **** | **** | **** | **** If your app market place isn't one of these you can pass your own store URL.
22+
1723
## Installation
1824
Install via npm
1925
```
@@ -26,6 +32,7 @@ Or if using Expo than you can use `expo install app-upgrade-react-native-sdk` as
2632
1. Register on App Upgrade and follow the instructions to create project and get the x-api-key.
2733

2834
2. Import the SDK and use it.
35+
### React Native Example
2936
```
3037
import {appUpgradeVersionCheck} from 'app-upgrade-react-native-sdk';
3138
@@ -61,19 +68,9 @@ const App: () => Node = () => {
6168
);
6269
};
6370
64-
```
65-
### Note:
66-
1. For opening the app store or play store the app should be live.
67-
2. It might not be able to open the app store or play store in simulator. You can try it in physical device.
68-
3. If you are using the same code base for both android and ios than you can detect the platform and provide the appId.
69-
4. You can find a sample app from here [app-upgrade-react-native-demo-app](https://github.com/appupgrade-dev/app_upgrade_react_native_demo_app)
70-
r. Read detailed blog on how to integrate from here [How to upgrade/force upgrade React Native app](https://appupgrade.dev/blog/how-to-force-upgrade-react-native-app)
71-
72-
```
73-
const appId = Platform.OS === 'android' ? 'com.android.chrome' : 'id310633997'
7471
```
7572

76-
Expo Example:
73+
### Expo Example:
7774
```
7875
import {appUpgradeVersionCheck} from 'app-upgrade-react-native-sdk';
7976
@@ -109,6 +106,74 @@ export default function App() {
109106
);
110107
}
111108
109+
```
110+
### Note:
111+
1. For opening the app store or play store the app should be live.
112+
2. It might not be able to open the app store or play store in simulator. You can try it in physical device.
113+
3. If you are using the same code base for both android and ios than you can detect the platform and provide the appId.
114+
4. You can find a sample app from here [app-upgrade-react-native-demo-app](https://github.com/appupgrade-dev/app_upgrade_react_native_demo_app)
115+
5. Read detailed blog on how to integrate from here [How to upgrade/force upgrade React Native app](https://appupgrade.dev/blog/how-to-force-upgrade-react-native-app)
116+
117+
### Example with store other than app store or play store.
118+
If you want users to redirect to store other than app store or playstore. You can add these additional parameters **preferredAndroidMarket** see the example below.
119+
```
120+
import {appUpgradeVersionCheck, PreferredAndroidMarket } from 'app-upgrade-react-native-sdk';
121+
122+
.....
123+
124+
const App: () => Node = () => {
125+
126+
const xApiKey = "MDNmNmZkNDEtNmNkMi00NzY3LThjOWEtYWYxMGFjZWQ0ZjI2"; // Your project key
127+
const appInfo = {
128+
appId: 'com.android.com' or 'id1549468967', // Your app url in play store or app store
129+
appName: 'Wallpaper app', // Your app name
130+
appVersion: '1.0.0', // Your app version
131+
platform: 'android', // App Platform, android or ios
132+
environment: 'production', // App Environment, production, development
133+
appLanguage: 'es' //Your app language ex: en, es etc. Optional.
134+
preferredAndroidMarket: PreferredAndroidMarket.AMAZON // or PreferredAndroidMarket.HUAWEI or PreferredAndroidMarket.OTHER If not provided default is Google playstore. Optional
135+
};
136+
137+
appUpgradeVersionCheck(appInfo, xApiKey);
138+
139+
return (
140+
<SafeAreaView style={backgroundStyle}>
141+
...
142+
</SafeAreaView>
143+
);
144+
};
145+
146+
```
147+
148+
If you want to redirect user to some other android market place you can use the following example:
149+
```
150+
import {appUpgradeVersionCheck, PreferredAndroidMarket } from 'app-upgrade-react-native-sdk';
151+
152+
.....
153+
154+
const App: () => Node = () => {
155+
156+
const xApiKey = "MDNmNmZkNDEtNmNkMi00NzY3LThjOWEtYWYxMGFjZWQ0ZjI2"; // Your project key
157+
const appInfo = {
158+
appId: 'com.android.com' or 'id1549468967', // Your app url in play store or app store
159+
appName: 'Wallpaper app', // Your app name
160+
appVersion: '1.0.0', // Your app version
161+
platform: 'android', // App Platform, android or ios
162+
environment: 'production', // App Environment, production, development
163+
appLanguage: 'es' //Your app language ex: en, es etc. Optional.
164+
preferredAndroidMarket: PreferredAndroidMarket.OTHER
165+
otherAndroidMarketUrl: 'https://someotherandroidmarket.com/app/id'// Required if preferredAndroidMarket is Other.
166+
};
167+
168+
appUpgradeVersionCheck(appInfo, xApiKey);
169+
170+
return (
171+
<SafeAreaView style={backgroundStyle}>
172+
...
173+
</SafeAreaView>
174+
);
175+
};
176+
112177
```
113178

114179
## Example Screenshot

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { versionCheck } from "./src/version-check";
22

3+
const PreferredAndroidMarket = {
4+
GOOGLE: 'Google',
5+
HUAWEI: 'Huawei',
6+
AMAZON: 'Amazon',
7+
OTHER: 'Other',
8+
}
9+
310
function appUpgradeVersionCheck(appInfo, xApiKey, alertInfo) {
411
versionCheck(appInfo, xApiKey, alertInfo);
512
}
613

7-
export { appUpgradeVersionCheck };
14+
export { appUpgradeVersionCheck, PreferredAndroidMarket };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "app-upgrade-react-native-sdk",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "Official App Upgrade react-native sdk",
55
"main": "index.js",
66
"scripts": {

src/validation.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PreferredAndroidMarket } from "app-upgrade-react-native-sdk";
2+
13
function validate(appInfo, xApiKey) {
24
if (!xApiKey || xApiKey === undefined || xApiKey === "") {
35
console.error("App Upgrade Validation Error: xApiKey is required.");
@@ -42,9 +44,28 @@ function validate(appInfo, xApiKey) {
4244
) {
4345
console.error("App Upgrade Validation Error: environment is required.");
4446
return false;
47+
} else if (
48+
appInfo.preferredAndroidMarket &&
49+
appInfo.preferredAndroidMarket === PreferredAndroidMarket.OTHER &&
50+
!appInfo.otherAndroidMarketUrl
51+
) {
52+
console.error(
53+
"App Upgrade Validation Error: otherMarketUrl is required when prefferedAndroidMarket is Other."
54+
);
55+
return false;
56+
} else if (
57+
appInfo.preferredAndroidMarket &&
58+
!Object.values(PreferredAndroidMarket).includes(
59+
appInfo.preferredAndroidMarket
60+
)
61+
) {
62+
console.error(
63+
"App Upgrade Validation Error: Unsupported prefferedAndroidMarket value."
64+
);
65+
return false;
4566
} else {
4667
return true;
4768
}
4869
}
4970

50-
export { validate };
71+
export { validate };

src/version-check.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { validate } from "./validation";
22
import { checkVersionWithAppUpgrade } from "./api";
33
import { Platform, Alert, Linking } from "react-native";
4+
import { PreferredAndroidMarket } from "app-upgrade-react-native-sdk";
45

56
async function versionCheck(appInfo, xApiKey, alertInfo) {
67
const isValid = validate(appInfo, xApiKey);
@@ -38,7 +39,7 @@ function showForceUpgradeAlert(appInfo, alertInfo, msg) {
3839
text: alertInfo.updateButtonTitle,
3940
onPress: () => {
4041
showForceUpgradeAlert(appInfo, alertInfo, msg)
41-
redirectToStore(appInfo.appId)
42+
redirectToStore(appInfo)
4243
},
4344
},
4445
],
@@ -60,7 +61,7 @@ function showUpgradeAlert(appInfo, alertInfo, msg) {
6061
},
6162
{
6263
text: alertInfo.updateButtonTitle,
63-
onPress: () => redirectToStore(appInfo.appId),
64+
onPress: () => redirectToStore(appInfo),
6465
},
6566
],
6667
{
@@ -71,12 +72,31 @@ function showUpgradeAlert(appInfo, alertInfo, msg) {
7172
);
7273
}
7374

74-
function redirectToStore(appId) {
75+
function redirectToStore(appInfo) {
7576
if (Platform.OS === 'android') {
76-
Linking.openURL(`https://play.google.com/store/apps/details?id=${appId}`);
77+
if (appInfo.preferredAndroidMarket === PreferredAndroidMarket.GOOGLE) {
78+
const url = `https://play.google.com/store/apps/details?id=${appInfo.appId}`
79+
openStore(url);
80+
} else if (appInfo.preferredAndroidMarket === PreferredAndroidMarket.HUAWEI) {
81+
const url = `appmarket://details?id=${appInfo.appId}`;
82+
openStore(url);
83+
} else if (appInfo.preferredAndroidMarket === PreferredAndroidMarket.AMAZON) {
84+
const url = `https://www.amazon.com/gp/mas/dl/android?p=${appInfo.appId}`;
85+
openStore(url);
86+
} else if (appInfo.preferredAndroidMarket === PreferredAndroidMarket.OTHER) {
87+
Linking.openURL(appInfo.otherAndroidMarketUrl);
88+
} else {
89+
Linking.openURL(`https://play.google.com/store/apps/details?id=${appInfo.appId}`);
90+
}
7791
} else {
78-
Linking.openURL(`https://apps.apple.com/app/id/${appId}`);
92+
Linking.openURL(`https://apps.apple.com/app/id/${appInfo.appId}`);
7993
}
8094
}
8195

96+
function openStore(url) {
97+
Linking.openURL(url).catch((err) => {
98+
console.debug("App Upgrade Error: ", err);
99+
})
100+
}
101+
82102
export { versionCheck };

0 commit comments

Comments
 (0)