Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App store country codes #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
## 0.3.2

- Fix for IOS

## 0.4.0

- Add country codes for App Store look-up
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ dependencies:
...
```

#### Or
If your app is not published in the US App Store, you can provide a list of countries where it's available:
```dart
final _checker = AppVersionChecker(
appStoreCountryCodes: ["DE", "US", "IT"]);
...
```

#### Use on ApkPure Store

```dart
Expand All @@ -51,4 +59,3 @@ dependencies:
);
...
```

2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.2"
version: "0.4.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
17 changes: 12 additions & 5 deletions lib/flutter_app_version_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ class AppVersionChecker {
/// default will be `AndroidStore.GooglePlayStore`
final AndroidStore androidStore;

/// The list of ISO-2A country codes used in the app look-up
/// if [appStoreCountryCodes] is null the look-up will be base in the US store only
final List<String>? appStoreCountryCodes;

AppVersionChecker({
this.currentVersion,
this.appId,
this.androidStore = AndroidStore.googlePlayStore,
this.appStoreCountryCodes,
});

Future<AppCheckerResult> checkUpdate() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
final _currentVersion = currentVersion ?? packageInfo.version;
final _packageName = appId ?? packageInfo.packageName;
final _countryCodes = appStoreCountryCodes ?? [];
if (Platform.isAndroid) {
switch (androidStore) {
case AndroidStore.apkPure:
Expand All @@ -40,20 +46,21 @@ class AppVersionChecker {
return await _checkPlayStore(_currentVersion, _packageName);
}
} else if (Platform.isIOS) {
return await _checkAppleStore(_currentVersion, _packageName);
return await _checkAppleStore(
_currentVersion, _packageName, _countryCodes);
} else {
return AppCheckerResult(_currentVersion, null, "",
'The target platform "${Platform.operatingSystem}" is not yet supported by this package.');
}
}

Future<AppCheckerResult> _checkAppleStore(
String currentVersion, String packageName) async {
Future<AppCheckerResult> _checkAppleStore(String currentVersion,
String packageName, List<String> countryCodes) async {
String? errorMsg;
String? newVersion;
String? url;
var uri =
Uri.https("itunes.apple.com", "/lookup", {"bundleId": packageName});
var uri = Uri.https("itunes.apple.com", "/lookup",
{"bundleId": packageName, "country": countryCodes});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be countryCodes.join(',')?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the iTunes API expect many country=<code> parameters rather than country=<code,code,code...>

try {
final response = await http.get(uri);
if (response.statusCode != 200) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_app_version_checker
description: A lightweight flutter plugin to check if your app is up-to-date on Google Play Store or Apple App Store
version: 0.3.2
version: 0.4.0
homepage: https://github.com/X-SLAYER/app_version_checker
documentation: https://github.com/X-SLAYER/app_version_checker

Expand Down