Xamarin.Forms如何在Android和iOS上添加应用程序评级?

时间:2019-04-30 10:44:41

标签: android ios xamarin.forms rating

哪个是在Xamarin.Forms应用程序上添加应用程序评级的最佳/最简单的选择,默认的星型表直接连接到Play商店或App Store?

3 个答案:

答案 0 :(得分:1)

Store Review Nuget plugin 最近已更新至 v3,这要归功于新的(2020 年 8 月)Android 原生 Play 核心库,因此它仅使用一行代码即可在 iOS 和 Android 上显示应用内评论:< /p>

await CrossStoreReview.Current.RequestReview(false);

所以现在,您不必担心在外部商店或网络视图中打开应用程序的 url,它将直接显示在应用程序中。您可以在 this Microsoft Blog

上查看更多详细信息

记得在README of the Nuget's GitHub repository

中提到的proguard文件中添加必要的代码

答案 1 :(得分:0)

在Android上,您必须打开PlayStore才能对应用进行评分;在iOS上,您可以在应用内进行操作,但只能从iOS 10开始。

您必须实现本机方法,并通过dependecy服务使用它。

界面

public interface IAppRating
{
    void RateApp();
}

Android

public class AppRatiing : IAppRating
{
    public void RateApp()
    {
        var activity = Android.App.Application.Context;
        var url = $"market://details?id={(activity as Context)?.PackageName}";

        try
        {
            activity.PackageManager.GetPackageInfo("com.android.vending", PackageInfoFlags.Activities);
            Intent intent = new Intent(Intent.ActionView, Uri.Parse(url));

            activity.StartActivity(intent);
        }
        catch (PackageManager.NameNotFoundException ex)
        {
            // this won't happen. But catching just in case the user has downloaded the app without having Google Play installed.

            Console.WriteLine(ex.Message);
        }
        catch (ActivityNotFoundException)
        {
            // if Google Play fails to load, open the App link on the browser 

            var playStoreUrl = "https://play.google.com/store/apps/details?id=com.yourapplicationpackagename"; //Add here the url of your application on the store

            var browserIntent = new Intent(Intent.ActionView, Uri.Parse(playStoreUrl));
            browserIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ResetTaskIfNeeded);

            activity.StartActivity(browserIntent);
        }
    }
}

iOS

public class AppRating : IAppRating
{
    public void RateApp()
    {
        if (UIDevice.CurrentDevice.CheckSystemVersion(10, 3))
            SKStoreReviewController.RequestReview();
        else
        {
            var storeUrl = "itms-apps://itunes.apple.com/app/YourAppId";
            var url = storeUrl + "?action=write-review";

            try
            {
                UIApplication.SharedApplication.OpenUrl(new NSUrl(url));
            }
            catch(Exception ex)
            {
                // Here you could show an alert to the user telling that App Store was unable to launch

                Console.WriteLine(ex.Message);
            }
        }
    }
}

答案 2 :(得分:0)

在Android上(经过9.0测试),我必须在FabriBertani´s解决方案中添加此标志:

activity.StartActivity(intent);