【问题标题】:Xamarin.Forms how to add app rating on Android and iOS?Xamarin.Forms 如何在 Android 和 iOS 上添加应用评​​级?
【发布时间】:2019-09-19 00:25:05
【问题描述】:

在 Xamarin.Forms 应用程序上添加应用评​​级的最佳/最简单选项是直接连接到 Play Store 或 App Store 的默认星形表单?

【问题讨论】:

  • @Jason 是的,但是这会在应用程序中打开应用程序商店中的应用程序的 url,就像 web 视图一样,我想直接在应用程序中显示表单
  • 阅读“请求审查”部分
  • @Jason Android 和 iOS 的“请求审查”是一样的吗?
  • 文档清楚地说“UWP 和 iOS”

标签: ios xamarin xamarin.forms xamarin.android xamarin.ios


【解决方案1】:

编辑:我为此创建了一个 nuget 包,您可以从Here 下载或查看GitHub repo

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

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

界面

public interface IAppRating
{
    void RateApp();
}

安卓

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);
            }
        }
    }
}

【讨论】:

  • @FabriBertrani,非常感谢,最后一个疑问,仅当用户使用该应用程序一段时间后,我如何控制和调用 RateApp() 方法?有没有办法让插件自动完成?
  • 我只是在应用程序启动和存储该计数器时使用了一个计数器,当计数器达到某个数字时,它会向用户显示一个对话框,询问他们是否要对应用程序进行评分(您需要这样做因为侵入性较小,Apple 会惩罚你)
  • 你好@FabriBertani,我使用了你的代码,它在 iPhone 模拟器上对我很有用,但是当我发布应用程序时,即使达到了计数器,评级弹出窗口也没有出现,你知道吗?请指教。使用的IOS是13.2
  • 您好@FadlAssaad,我已经在 iOS 13.2 上进行了测试并且工作正常,也许您应该检查发布模式下可能发生的其他问题。干杯
  • 如果任何人的文件中有using System,请注意您需要完全限定Uri 类:Android.Net.Uri.Parse(url)
【解决方案2】:

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

activity.StartActivity(intent);

【讨论】:

    【解决方案3】:

    Store Review Nuget plugin 最近已更新到 v3,这要归功于新的(2020 年 8 月)Android 原生 Play Core 库,因此它只需一行代码即可在 iOS 和 Android 上显示应用内评论:

    await CrossStoreReview.Current.RequestReview(false);
    

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

    只记得在README of the Nuget's GitHub repository提到的proguard文件中添加必要的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 2011-06-14
      • 2019-03-08
      • 1970-01-01
      相关资源
      最近更新 更多