首页 > 解决方案 > 如何检查版本号并在 App(iTunes)Store (iOS) 中打开应用程序?

问题描述

我需要检查已安装应用程序的当前版本。如果不是同一个应用程序,则应导航到应用程序商店中的应用程序页面。

我正在为此使用最新版本的插件。它可以正常工作Android但不能正常工作iOS

Setings.appVersion = await CrossLatestVersion.Current.GetLatestVersionNumber();
if (Setings.appVersion == "1.0.1")
{
     MainPage = new NavigationPage(new Login());
}
else
{
     //lblBuildNumber.Text = DependencyService.Get<IAppVersionAndBuild>().GetBuildNumber();
     MainPage = new NavigationPage(new UpdateAppPopup());
}


async void  Handle_Clicked(object sender, System.EventArgs e)
{
      await CrossLatestVersion.Current.OpenAppInStore("com.KIH.Consultant");
}

使用此代码,它应该导航到应用商店或 Playstore 中的应用页面

标签: pluginsxamarin.formsxamarin.ios

解决方案


1) 在主项目中创建一个接口

public interface IAppService
{
  string GetVersion();
}

2)然后在你的机器人项目中实现它

public class AppService : IAppService
{

    public string GetVersion() {
    var context = Android.App.Application.Context;
    var info = context.PackageManager.GetPackageInfo(context.PackageName, 
    Android.Content.PM.PackageInfoFlags.MatchAll);
    return info.VersionName;
}

3)然后在你的ios项目中实现它

public class AppService : IAppService
{
    public string GetVersion()
    {
        return NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"].ToString();
    }
}

4)现在你可以像这样使用它

string v = Get<IAppService>().GetVersion();

推荐阅读