如何使用Swift / iOS获取App Store中最新应用版本的版本字符串属性的内容?

时间:2015-09-01 12:44:58

标签: ios swift ios8 app-store

亲爱的堆栈溢出社区,

我希望使用Swift根据App ID获取应用商店中最新版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。任何帮助赞赏。感谢

1 个答案:

答案 0 :(得分:0)

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

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