plugins - 如何检查版本号并在 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 中的应用页面
解决方案
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();
推荐阅读
- javascript - node.js 中的 SOAP 请求
- javascript - 纯js下拉菜单中的搜索结果
- android - Android 应用漏洞 - HostnameVerifier,不在代码库中的任何位置
- delphi - 使用 Delphi 消息队列避免重复触发昂贵的操作
- ruby-on-rails - 将现有数据库中的数据播种到 Rails 中的新数据库
- firebase - Firestore UID 会被劫持吗?
- android - Android:FCM 通知显示不正确
- java - 跳过 xsl:for-each 迭代时 xsl:number 递增
- javascript - 如何在我的 React 应用程序中避免 eval 以及您对逻辑的看法?
- sql - Oracle 触发器错误 - ORA-04080:触发器“TRIG”不存在