一.
最开始查资料,方式是通过以下API获得版本json:
http://itunes.apple.com/lookup?id=1329918420
然后我通过app store connect里面的my apps我的app的信息页面查看到app id.替换下去后发现返回0,没有app的结果.
又从官方文档里查看到:
https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/#lookup
Look up Jack Johnson by iTunes artist ID:
https://itunes.apple.com/lookup?id=909253
这个id 是artist id,那么为什么示例的可以查看到app的信息,但是我的又不行呢?
二.
后来从另外一篇文章里看到:
https://stackoverflow.com/questions/6256748/check-if-my-app-has-a-new-version-on-appstore
里面使用:
http://itunes.apple.com/lookup?bundleId=\(identifier)
bundle id,那么怎么获得我的app的bundle id呢?还是原来app store connect里面查看app信息的页面,在综合信息里面有三个id,一个是套装id,一个是sku,一个是app id.那么套装id就是bundle id了.
然后替换进去发现成功了.
三.
以下是完整获得version的代码:
-(void)getWebVersion{
//对请求路径的说明
//http://120.25.226.186:32812/login?username=520it&pwd=520&type=JSON
//协议头+主机地址+接口名称+?+参数1&参数2&参数3
//协议头(http://)+主机地址(120.25.226.186:32812)+接口名称(login)+?+参数1(username=520it)&参数2(pwd=520)&参数3(type=JSON)
//GET请求,直接把请求参数跟在URL的后面以?隔开,多个参数之间以&符号拼接
//1.确定请求路径
// NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=1329918420"];
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/hk/lookup?bundleId=com.xx.foo"];
//2.创建请求对象
//请求对象内部默认已经包含了请求头和请求方法(GET)
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//3.获得会话对象
NSURLSession *session = [NSURLSession sharedSession];
//4.根据会话对象创建一个Task(发送请求)
/*
第一个参数:请求对象
第二个参数:completionHandler回调(请求完成【成功|失败】的回调)
data:响应体信息(期望的数据)
response:响应头信息,主要是对服务器端的描述
error:错误信息,如果请求失败,则error有值
*/
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error == nil) {
//6.解析服务器返回的数据
//说明:(此处返回的数据是JSON格式的,因此使用NSJSONSerialization进行反序列化处理)
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"dict %@",dict);
// NSDictionary *appInfo = (NSDictionary*)data;
NSArray *infoContent = [dict objectForKey:@"results"];
NSString * version = [[infoContent objectAtIndex:0]objectForKey:@"version"];//线上最新版本
NSLog(@"version %@",version);
_webAppVersion = version;
}else{
_webAppVersion = @"0";
}
[self handleVersionCheckResult];
}];
//5.执行任务
[dataTask resume];
}