Skip to content

Commit

Permalink
Merge pull request #13 from Innim/master
Browse files Browse the repository at this point in the history
Ability to check app review support. Fix error, docs, improvements.
  • Loading branch information
rodydavis committed Feb 4, 2020
2 parents 8fa21f5 + 02c4807 commit 8b7b41f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
11 changes: 7 additions & 4 deletions ios/Classes/SwiftAppReviewPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ public class SwiftAppReviewPlugin: NSObject, FlutterPlugin {
result("Later than iOS 10.3 the App will Request the App Review, Users can turn this off in settings for all apps, Apple will manage when to request the review from the user. In Debug it will always show. Requesting review for: " + appID)
} else {
// Fallback on earlier versions
let urlStr = "itms-apps://itunes.apple.com/app/viewContentsUserReviews?id=\(appID)" // Open App Review Tab
if let url = URL(string: urlStr), UIApplication.shared.canOpenURL(url) {
result("If the app is not published the app will not be found. Prior to iOS 10.3 (Going to Store Page of App): " + appID)
}
result("Prior to iOS 10.3 App Review from App is not available. You should go to Store Page of App: " + appID + ". If the app is not published the app will not be found.")
}
case "isRequestReviewAvailable":
if #available(iOS 10.3, *) {
result("1")
} else {
result("0")
}
default:
result(FlutterMethodNotImplemented)
Expand Down
42 changes: 38 additions & 4 deletions lib/app_review.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import 'package:url_launcher/url_launcher.dart';
class AppReview {
static const MethodChannel _channel = MethodChannel('app_review');

/// Request review.
///
/// Tells StoreKit to ask the user to rate or review your app, if appropriate.
/// Supported only in iOS 10.3+ (see [isRequestReviewAvailable]).
///
/// Returns string with details message.
static Future<String> get requestReview async {
if (Platform.isIOS) {
final String details = await _channel.invokeMethod('requestReview');
Expand All @@ -20,6 +26,19 @@ class AppReview {
}
}

/// Check if [requestReview] feature available.
static Future<bool> get isRequestReviewAvailable async {
if (Platform.isIOS) {
final String result = await _channel.invokeMethod('isRequestReviewAvailable');
return result == "1";
} else {
return false;
}
}

/// Open store page with action write review.
///
/// Supported only for iOS, on Android [storeListing] will be executed.
static Future<String> get writeReview async {
if (Platform.isIOS) {
final String _appID = await getiOSAppID;
Expand All @@ -41,12 +60,19 @@ class AppReview {
}
}

/// Navigates to Store Listing in Google Play/App Store.
///
/// Returns string with details message.
static Future<String> get storeListing async {
String details = '';
if (Platform.isIOS) {
final String _appID = await getiOSAppID;
await launch('https://itunes.apple.com/app/id$_appID?');
details = 'Launched App Store';
if (_appID.isNotEmpty) {
await launch('https://itunes.apple.com/app/id$_appID?');
details = 'Launched App Store';
} else {
details = 'Not found in App Store';
}
} else {
final String _appID = await getAppID;
if (await canLaunch("market://")) {
Expand All @@ -61,6 +87,7 @@ class AppReview {
return details;
}

/// Returns package name for application.
static Future<String> get getAppID async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();

Expand All @@ -75,15 +102,22 @@ class AppReview {
return packageName;
}

/// Returns Apple ID for iOS application.
///
/// If there is no such application in App Store - returns empty string.
static Future<String> get getiOSAppID async {
final String _appID = await getAppID;
String _id = '';
await http
.get('http://itunes.apple.com/lookup?bundleId=$_appID')
.then((dynamic response) {
final Map<String, dynamic> _json = json.decode(response.body);
_id = _json['results'][0]['trackId'].toString();
print('Track ID: $_id');
if (_json['resultCount'] > 0) {
_id = _json['results'][0]['trackId'].toString();
print('Track ID: $_id');
} else {
print('Application with bundle "$_appID" is not found on App Store');
}
});
return _id;
}
Expand Down

0 comments on commit 8b7b41f

Please sign in to comment.