簡體   English   中英

Xamarin.Forms 如何在 Android 和 iOS 上添加應用評​​級?

[英]Xamarin.Forms how to add app rating on Android and iOS?

在 Xamarin.Forms 應用程序(直接連接到 Play 商店或 App Store 的默認星形表格)上添加應用評​​級的最佳/最簡單選項是哪個?

編輯:我為此創建了一個 nuget 包,您可以從這里下載或查看GitHub 存儲庫

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

在 Android 上(在9.0測試),我必須在FabriBertani 的解決方案中添加此標志:

activity.StartActivity(intent);

借助新的(2020 年 8 月)Android 原生 Play Core 庫, Store Review Nuget 插件最近已更新到 v3,因此它僅使用一行代碼即可在 iOS 和 Android 上顯示應用內評論:

await CrossStoreReview.Current.RequestReview(false);

所以現在,您不必擔心在外部商店或網絡視圖中打開應用程序的 url,它將直接顯示在應用程序中。 您可以在 此 Microsoft 博客上查看更多詳細信息

只需記住在 Nuget 的 GitHub 存儲庫README 中提到的 proguard 文件中添加必要的代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM