Xamarin.ios 检查appstore应用程序版本xmarin(强制升级应用程序)

Xamarin.ios 检查appstore应用程序版本xmarin(强制升级应用程序),xamarin.ios,Xamarin.ios,在xamarin.ios或xamarin.android或mvvmcross5中是否有方法检查appstore中应用程序的版本号 有人能帮我转到一个样本吗?给你。我找到了解决方案: private string GetAppStoreAppVersion() { string appStoreAppVersion = string.Empty; try { var dicti

在xamarin.ios或xamarin.android或mvvmcross5中是否有方法检查appstore中应用程序的版本号


有人能帮我转到一个样本吗?

给你。我找到了解决方案:

private string GetAppStoreAppVersion()
        {
            string appStoreAppVersion = string.Empty;

            try
            {
                var dictionary = NSBundle.MainBundle.InfoDictionary;
                string applicationID = dictionary[@"CFBundleIdentifier"].ToString();


                NSUrl url = new NSUrl($"http://itunes.apple.com/lookup?bundleId={applicationID}");
                NSData data = NSData.FromUrl(url);
                NSError error = new NSError();
                NSDictionary lookup = NSJsonSerialization.Deserialize(data, 0, out error) as NSDictionary;

                if (error == null
                    && lookup != null
                    && lookup.Keys.Length >= 1
                    && lookup["resultCount"] != null
                    && Convert.ToInt32(lookup["resultCount"].ToString()) > 0)
                {

                    var results = lookup[@"results"] as NSArray;

                    if (results != null && results.Count > 0)
                    {
                        appStoreAppVersion = results.GetItem<NSDictionary>(0)["version"].ToString();

                    }
                }

            }
            catch (Exception ex)
            {
                //No need to throw an exception if version check fails 
            }


            return appStoreAppVersion;
        }
私有字符串GetAppStoreAppVersion()
{
string appStoreAppVersion=string.Empty;
尝试
{
var dictionary=NSBundle.MainBundle.InfoDictionary;
字符串applicationID=dictionary[@“CbundleIdentifier”].ToString();
NSUrl url=新的NSUrl($”http://itunes.apple.com/lookup?bundleId={applicationID}”);
NSData data=NSData.FromUrl(url);
NSError error=新的NSError();
NSDictionary lookup=NSJsonSerialization。反序列化(数据,0,输出错误)为NSDictionary;
if(error==null)
&&查找!=null
&&lookup.Keys.Length>=1
&&查找[“结果计数”]!=null
&&Convert.ToInt32(查找[“resultCount”].ToString())>0)
{
var结果=查找[@“结果”]作为NSArray;
if(results!=null&&results.Count>0)
{
appStoreAppVersion=results.GetItem(0)[“版本”].ToString();
}
}
}
捕获(例外情况除外)
{
//如果版本检查失败,则无需引发异常
}
返回appStoreAppVersion;
}

如果您希望在后端实现此功能,那么下面是获得此功能的代码

string url = "http://itunes.apple.com/lookup?bundleId=yourbundleid";

            using (var webClient = new System.Net.WebClient())
            {
                string jsonString = webClient.DownloadString(string.Format(url));

                var lookup = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);


                if (lookup != null
                    && lookup.Count >= 1
                    && lookup["resultCount"] != null
                    && Convert.ToInt32(lookup["resultCount"].ToString()) > 0)
                {

                    var results = JsonConvert.DeserializeObject<List<object>>(lookup[@"results"].ToString());


                    if (results != null && results.Count > 0)
                    {
                        var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(results[0].ToString());
                        appStoreAppVersion = values.ContainsKey("version") ? values["version"].ToString() : string.Empty;

                    }
                }
            }

            return appStoreAppVersion;
stringurl=”http://itunes.apple.com/lookup?bundleId=yourbundleid";
使用(var webClient=new System.Net.webClient())
{
string jsonString=webClient.DownloadString(string.Format(url));
var lookup=JsonConvert.DeserializeObject(jsonString);
if(查找!=null
&&查找。计数>=1
&&查找[“结果计数”]!=null
&&Convert.ToInt32(查找[“resultCount”].ToString())>0)
{
var results=JsonConvert.DeserializeObject(查找[@“results”].ToString());
if(results!=null&&results.Count>0)
{
var values=JsonConvert.DeserializeObject(结果[0].ToString());
appStoreAppVersion=values.ContainsKey(“版本”)?values[“version”].ToString():string.Empty;
}
}
}
返回appStoreAppVersion;

可能重复@Jason,但不重复,因为该问题/答案适用于swift,而该问题/答案适用于xamarin.ios