2017-10-18 1 views
1

Gibt es einen Weg in Xamarin.ios oder Xamarin.android oder MVVMCross5, um die Versionsnummer der App im Appstore zu überprüfen?AppStore App Version Xmarin (Force Upgrade der App)

Kann mich jemand bitte zu einer Probe umleiten?

+0

Mögliche Duplikat [Überprüfen Sie, ob meine app eine neue Version im Appstore hat] (https://stackoverflow.com/questions/6256748/check-if-my-app-has-a-new-version- On-App-Store) – Jason

Antwort

0

Hier gehen Sie. Ich habe eine Lösung dafür gefunden:

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; 
     } 
0

Wenn Sie suchen, dies im Backend zu implementieren, dann hier ist der Code, um es zu bekommen.

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; 
Verwandte Themen