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

时间:2022-01-15 07:21:47

Dear stack overflow community,

亲爱的堆栈溢出社区,

I wish to get the content of the version string property of the latest version of my iOS app available in the app store, based on the App ID, using Swift.

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

Basically I want to change the following Objective-C code to relate on the App ID instead of the bundle ID and I wish to translate it to Swift:

基本上我想更改以下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"];
}

While I should be able to translate the code to swift pretty easily I don't know yet how to make it depend on the App ID instead of the bundle ID. Any help appreciated. Thanks

虽然我应该能够很容易地将代码转换为swift,但我还不知道如何使它依赖于App ID而不是bundle ID。任何帮助赞赏。谢谢

1 个解决方案

#1


0  

I'm not sure which field you mean when you say "App ID" but the way you can find the answer is to open your info.plist file in Xcode, right click in the file content area, and choose Show Raw Keys/Values.

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

You'll see the key CFBundleIdentifier that represents the bundle id. Find the corresponding key that matches the "App ID" that you want to use and substitute it in the code you're going to convert. (CFBundleExecutable maybe?)

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

#1


0  

I'm not sure which field you mean when you say "App ID" but the way you can find the answer is to open your info.plist file in Xcode, right click in the file content area, and choose Show Raw Keys/Values.

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

You'll see the key CFBundleIdentifier that represents the bundle id. Find the corresponding key that matches the "App ID" that you want to use and substitute it in the code you're going to convert. (CFBundleExecutable maybe?)

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