簡體   English   中英

如何使用Swift / iOS在App Store中獲得最新應用程序版本的版本字符串屬性的內容?

[英]How can I get the content of the version string property of my latest app version available in the App Store using Swift/ iOS?

親愛的堆棧溢出社區,

我希望使用Swift獲取基於App ID的iOS應用程序最新版本的版本字符串屬性的內容。

基本上,我想更改以下Objective-C代碼以與App ID而不是包ID關聯,我希望將其轉換為Swift:

NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* bundleID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", bundleID]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

if ([lookup[@"resultCount"] integerValue] == 1){
    NSString* appStoreVersion = lookup[@"results"][0][@"version"];
}

雖然我應該能夠輕松地轉換代碼,但是我仍然不知道如何使其依賴於App ID而不是bundle ID。 任何幫助表示贊賞。 謝謝

我不確定當您說“ App ID”時您指的是哪個字段,但是找到答案的方法是在Xcode中打開info.plist文件,右鍵單擊文件內容區域,然后選擇“顯示原始鍵/值” 。

您將看到代表包ID的鍵CFBundleIdentifier。 找到與您要使用的“應用程序ID”匹配的對應密鑰,並將其替換為要轉換的代碼。 (也許CFBundleExecutable?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM