如何使用 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?

亲爱的堆栈溢出社区,

我希望根据应用程序 ID,使用 Swift 获取我的 iOS 应用程序最新版本的版本字符串 属性 的内容.

基本上我想更改以下 Objective-C 代码以与 App ID 而不是 bundle 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"];
}

虽然我应该能够很容易地将代码翻译成 swift,但我还不知道如何让它依赖于 App ID 而不是 bundle ID。任何帮助表示赞赏。谢谢

我不确定你说 "App ID" 时指的是哪个字段,但找到答案的方法是打开 Xcode 中的 info.plist 文件,右键单击文件内容区域,然后选择 Show Raw Keys/Values.

您将看到表示包 ID 的键 CFBundleIdentifier。找到与您要使用的 "App ID" 相匹配的相应密钥,并将其替换为您要转换的代码。 (也许是 CFBundleExecutable?)