我正在开发一个Xamarin.Forms应用,但iOS版本似乎没有正确显示。
我将info.plist
设置为Version:0.0和Build:9,但在应用程序中显示为版本1.5.174和Build 674
[assembly: Xamarin.Forms.Dependency(typeof(SocialNetwork.iOS.Version_iOS))]
namespace SocialNetwork.iOS
{
public class Version_iOS : IAppVersion
{
public string GetVersion()
{
return NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
}
public int GetBuild()
{
return int.Parse(NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString());
}
}
}
IAppVersion就是
public interface IAppVersion
{
string GetVersion();
int GetBuild();
}
我使用
获取值public static string AppVersion = DependencyService.Get<IAppVersion>().GetVersion();
public static int AppBuild = DependencyService.Get<IAppVersion>().GetBuild();
答案 0 :(得分:3)
<强> SHARED 强>
声明:的
public interface IYourName
{
string GetAppVersion();
}
用法:
var AppVersion = DependencyService.Get<IYourName>().GetAppVersion();
<强> IOS 强>
//****************************************************
class YourNameHelpers : IYourName
//****************************************************
{
//-------------------------------------------------------------
public string GetAppVersion()
//-------------------------------------------------------------
{
return NSBundle.MainBundle.InfoDictionary[new NSString("CFBundleVersion")].ToString();
}
}
<强>的Android 强>
//****************************************************
class YourNameHelpers : IYourName
//****************************************************
{
//-------------------------------------------------------------
public string GetAppVersion()
//-------------------------------------------------------------
{
Context context = Forms.Context;
PackageManager manager = context.PackageManager;
PackageInfo info = manager.GetPackageInfo(context.PackageName, 0);
return info.VersionName;
}
}