Plugin.XamarinAppRating 1.2.2

dotnet add package Plugin.XamarinAppRating --version 1.2.2                
NuGet\Install-Package Plugin.XamarinAppRating -Version 1.2.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.XamarinAppRating" Version="1.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.XamarinAppRating --version 1.2.2                
#r "nuget: Plugin.XamarinAppRating, 1.2.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plugin.XamarinAppRating as a Cake Addin
#addin nuget:?package=Plugin.XamarinAppRating&version=1.2.2

// Install Plugin.XamarinAppRating as a Cake Tool
#tool nuget:?package=Plugin.XamarinAppRating&version=1.2.2                

Plugin.XamarinAppRating

NuGet

Plugin.XamarinAppRating gives developers a fast and easy way to ask users to rate the app in the stores.

Installation

Plugin.XamarinAppRating is available via NuGet, grab the latest package and install it in your solution:

Install-Package Plugin.XamarinAppRating

Platforms supported

Platform Version
Xamarin.Android API 25+
Xamarin.iOS iOS 9.0+
Xamarin.tvOS All
Xamarin.macOS All
UWP Build 18362+

Version 1.2.2

New Features

  • Added support to macOS and tvOS ❗
  • Bug fixes and improvement.

API Usage

Call CrossAppRating.Current from any project to gain access to the APIs.

There are two main methods, PerformInAppRateAsync and PerformRatingOnStoreAsync.

Android

/// <summary>
/// Perform rating without leaving the app.
/// </summary>
public Task PerformInAppRateAsync();

This method will open an in-app review dialog, using the packageName declared on the AndroidManifest file.

/// <summary>
/// Perform rating on the current OS store app or open the store page on browser.
/// </summary>
public Task PerformRatingOnStoreAsync()

This method will open Google Play app on the store page of your current application. Otherwise, it will try to open the store page on the browser.

If neither the store page nor the browser store page works, it will display an alert announcing the error.

packageName must be provided as a named argument to open the store page on the store app or browser.

Example
if (CrossAppRating.IsSupported)
    await CrossAppRating.Current.PerformRatingOnStoreAsync(packageName: "com.facebook.katana");

iOS / macOS / tvOS

/// <summary>
/// Perform rating without leaving the app.
/// </summary>
public Task PerformInAppRateAsync();

For iOS: if the device's current OS version is 10.3 or newer, this method will raise an in-app review popup of your current application, otherwise, it will display an alert announcing that it's not supported.

/// <summary>
/// Perform rating on the current OS store app or open the store page on browser.
/// </summary>
public Task PerformRatingOnStoreAsync()

This method will open App Store app on the store page of your current application. Otherwise, it will try to open the store page on the browser.

If the method fails, it will display an alert announcing the error.

applicationId property is the StoreId of your app and it must be provided as a named argument to open the store page on the store app or browser.

Example
if (CrossAppRating.IsSupported)
    await CrossAppRating.Current.PerformRatingOnStoreAsync(applicationId: "id284882215");

UWP

/// <summary>
/// Perform rating without leaving the app.
/// </summary>
public Task PerformInAppRateAsync();

If the target version build is 17763 or above, this method will raise an in-app review dialog of your current application, otherwise, it will display an alert announcing that it's not supported.

/// <summary>
/// Perform rating on the current OS store app or open the store page on browser.
/// </summary>
public Task PerformRatingOnStoreAsync()

This method will open Microsoft Store application with the page of your current app.

If the method fails it will display an alert announcing the error.

productId is the ProductId of your UWP app and it must be provided as a named argument to open the store page app.

Example

if (CrossAppRating.IsSupported)
    await CrossAppRating.Current.PerformRatingOnStoreAsync(productId: "9wzdncrf0083");

Usage

⚠️ Warning - You should be careful about how and when you ask users to rate your app, there may be penalties from stores. As for advice, I recommend using a counter on the app start and storage that count, then when the counter reaches a certain number, display a dialog asking the users if they want to rate the app, if they decline the offer, reset the counter to ask them later, also leave the option to do it themselves.

public partial class MainPage : ContentPage
{
    private const string androidPackageName = "com.facebook.katana";
    private const string iOSApplicationId = "id284882215";
    private const string uwpProductId = "9wzdncrf0083";

    public MainPage()
    {
        InitializeComponent();

        if (!Preferences.Get("application_rated", false))
            Task.Run(() => CheckAppCountAndRate());
    }

    private async Task CheckAppCountAndRate()
    {
        if (Preferences.Get("application_counter", 0) >= 5)
        {
            if (!await DisplayAlert("Rate this App!", "Are you enjoying the app so far? Would you like to leave a review in the store?", "Yes", "No"))
            {
                Preferences.Set("application_counter", 0);

                return;
            }

            await RateApplicationInApp();
        }
    }

    private Task RateApplicationInApp()
    {
        if (CrossAppRating.IsSupported)
        {
            Device.BeginInvokeOnMainThread(async () =>
            {
                // This method will simulate Facebook™ app to in-app rating as example.
                await CrossAppRating.Current.PerformInAppRateAsync();
            });

            Preferences.Set("application_rated", true);
        }

        return Task.CompletedTask;
    }

    private Task RateApplicationOnStore()
    {
        if (CrossAppRating.IsSupported)
        {
            Device.BeginInvokeOnMainThread(async () =>
            {
                // This method use Facebook™'s store apps as example.
                await CrossAppRating.Current.PerformRatingOnStoreAsync(packageName: androidPackageName, applicationId: iOSApplicationId, productId: uwpProductId);
            });

            Preferences.Set("application_rated", true);
        }

        return Task.CompletedTask;
    }

    private void InAppRating_Clicked(object sender, EventArgs e)
    {
        if (!Preferences.Get("application_rated", false))
            Task.Run(() => RateApplicationInApp());
    }

    private void AppRateOnStore_Clicked(object sender, EventArgs e)
    {
        if (!Preferences.Get("application_rated", false))
            Task.Run(() => RateApplicationOnStore());
    }
}

Samples

Take a look at the TestApp sample for Xamarin.Forms or TestAppNative sample for Xamarin native fully detailed implementation of this plugin.

Contributions

Please, feel free to open an Issue if you found any bugs or submit a PR.

License

XamarinAppRating is licensed under MIT.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed.  monoandroid12.0 is compatible. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap10.0.18362 is compatible. 
Xamarin.iOS xamarinios was computed.  xamarinios10 is compatible. 
Xamarin.Mac xamarinmac was computed.  xamarinmac20 is compatible. 
Xamarin.TVOS xamarintvos was computed.  xamarintvos10 is compatible. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.2 4,040 4/17/2023
1.2.1 1,580 12/30/2021
1.2.0 660 4/28/2021
1.1.0 704 11/5/2020
1.0.1 592 10/11/2020
1.0.0 474 10/10/2020