not*_*eal 5 xamarin.ios xamarin.android ios xamarin xamarin.forms
在 Xamarin.Forms 应用程序(直接连接到 Play 商店或 App Store 的默认星形表格)上添加应用评级的最佳/最简单选项是哪个?
编辑:我为此创建了一个 nuget 包,您可以从这里下载或查看GitHub 存储库。
在 Android 上,您必须打开 PlayStore 才能对应用程序进行评分,在 iOS 上,您可以在应用程序内执行此操作,但只能从 iOS 10 开始。
您必须实现本机方法并通过依赖服务使用它。
界面
public interface IAppRating
{
void RateApp();
}
Run Code Online (Sandbox Code Playgroud)
安卓
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3624 次 |
最近记录: |