2017-06-01 31 views
1

我已經實施了一些代碼來檢查appStore版本是否高於當前的應用程序版本,並在這種情況下顯示彈出到用戶更新。版本信息是不正確的從iTunes(編程Objective-C)

我使用下面的代碼: -

NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; 
NSString *appStoreURL = [@"http://itunes.apple.com/lookup?bundleId="stringByAppendingString:bundleIdentifier]; 

// Get the main bundle of the app so that we can determine the app's version number 
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; 
NSString *appVersion = [infoDict objectForKey:@"CFBundleShortVersionString"]; // example: 1.0.0 

NSData *dict = [NSData dataWithContentsOfURL:[NSURL 
URLWithString:appStoreURL]]; 
NSError* error; 
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:dictoptions:kNilOptions error:&error]; 
NSLog(@"%@", json); 

,當我從URL獲取內容編程然後它給了版本「2.5」。請參考以下: -

enter image description here

但是,當我從瀏覽器下載的文本文件就說明我的版本「2.6」請參照下從TextEdit下面的截圖。

enter image description here

任何人都面臨着同樣的問題?

回答

1

做這將需要通常6-8個小時來獲得應用程序的新版本程序。目前,我在我的應用程序中使用相同的代碼,並且工作正常。您的代碼很好,只需等待Apple查找URL中的正確字典即可。

+0

感謝和現在的工作! –

0

它可能會解決你的問題,我在迅速3

let currentAppVersion = Bundle.main.infoDictionary 
    Alamofire.request("http://itunes.apple.com/jp/lookup/?id=app_Id", method: .get, parameters: nil, headers: nil).responseJSON { response in 
     if let value = response.result.value as? [String: AnyObject] { 
      let versionNum = value["results"]?.value(forKey: "version") as? NSArray 
      if versionNum?[0] as! String != currentAppVersion?["CFBundleShortVersionString"] as! String { 
       self.alertForUpdateApp(versionNo: versionNum?[0] as! String) 
      } 
     } 
    } 
+0

謝謝我的代碼工作。這只是iTunes的延遲。 –

+0

好吧,這太好了。 –