ios - Xamarin.Forms 如何在 Android 和 iOS 上添加应用评​​分?

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

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

最佳答案

编辑 : 我为此创建了一个 nuget 包,您可以从 Here 下载或查看GitHub repo .
在 Android 上,您必须打开 PlayStore 才能对应用进行评分,在 iOS 上,您可以在应用内进行,但只能从 iOS 10 开始。
您必须实现 native 方法并通过依赖服务使用它。
接口(interface)

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

关于ios - Xamarin.Forms 如何在 Android 和 iOS 上添加应用评​​分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55919274/

相关文章:

ios - 如何使用 Realm 和 Swift 从 TableView 中删除一个部分和一行?

xamarin - 未处理的异常 : System. TypeLoadException:无法使用 token 0100003b 解析类型

ios - 如何从音频处理中锁定数组以进行分析

c# - 在 Xamarin Forms visual studio 中向布局添加渐变背景

c# - 从 Xamarin 表单中的 Listview 获取选中的值

ios - 在 xamarin iOS 中旋转 UIImage

Xamarin 表单 : Add Clear Entry

azure - 在本地测试 Azure 托管的 WebApi 以将推送通知发送到所有设备

iphone - 用于紧急响应的 iOS 应用程序 - 如何在没有密码的情况下保护数据?

ios - Xamarin iOS c__AnonStorey1