下面两个接口都可以获取相同的数据,就是App的各种信息
https://itunes.apple.com/cn/lookup?id=AppleID ,为您的 App 自动生成的 ID.
https://itunes.apple.com/cn/lookup?bundleId=app的Bundle Identifier
下面为接口中获取App的各种信息,对应的值仅为个人对比猜测,看看就好
{
"resultCount":1,
"results": [
{"artistViewUrl":"AppStore中,开发人员其他App",
"artworkUrl60":"App的icon缩略图60x60大小",
"artworkUrl100":"App的icon缩略图100x100大小",
"ipadScreenshotUrls":[],
"appletvScreenshotUrls":[],
"artworkUrl512":"App的icon图512x512大小",
"isGameCenterEnabled":false,
"kind":"software",
"features":[],
"supportedDevices":["iPhone4S",
"iPhone5",
"iPodTouchFifthGen",
"iPhone5c",
"iPhone5s",
"iPhone6",
"iPhone6Plus",
"iPodTouchSixthGen"], //适配的手机型号
"advisories":[],
"screenshotUrls":["屏幕快照1",
"屏幕快照2",
"屏幕快照3"...],
"trackCensoredName":"App名称-AppStore中显示的名称",
"trackViewUrl":"App下载地址",
"contentAdvisoryRating":"4+",
"fileSizeBytes":"上传时的文件大小",
"languageCodesISO2A":["主要语言"],
"sellerUrl":"AppStore中,开发人员网站",
"trackContentRating":"4+",
"minimumOsVersion":"AppStore中,兼容性",
"currency":"CNY",
"wrapperType":"software",
"version":"版本号",
"artistId":1006567848,
"artistName":"AppStore中,开发商",
"genres":["分类1", "分类2"...],//上架App时所选 ,最能准确描述此 App 的类别。
"price":0.00,
"description":"App描述",
"trackId":"Apple ID ,为您的 App 自动生成的 ID。",
"trackName":"App名称-Display Name",
"bundleId":"Bundle Identifier",
"releaseDate":"App上架时间",
"primaryGenreName":"Medical",
"isVppDeviceBasedLicensingEnabled":true,
"currentVersionReleaseDate":"AppStore中,更新日期",
"formattedPrice":"免费",
"releaseNotes":"AppStore中,最新动态",
"sellerName":"开发商",
"primaryGenreId":6020,
"genreIds":["6020", "6013"]
}
]
}
上代码
//判断是否需要提示更新App
- (void)shareAppVersionAlert {
if(![self judgeNeedVersionUpdate]) return ;
//App内info.plist文件里面版本号
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = infoDict[@"CFBundleShortVersionString"];
NSString *bundleId = infoDict[@"CFBundleIdentifier"];
NSString *urlString = [NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?bundleid=%@", bundleId];
//两种请求appStore最新版本app信息 通过bundleId与appleId判断
//[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?bundleid=%@", bundleId]
//[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@", appleid]
NSURL *urlStr = [NSURL URLWithString:urlString];
//创建请求体
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlStr];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
if (connectionError) {
// NSLog(@"connectionError->%@", connectionError.localizedDescription);
return ;
}
NSError *error;
NSDictionary *resultsDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
if (error) {
// NSLog(@"error->%@", error.localizedDescription);
return;
}
NSArray *sourceArray = resultsDict[@"results"];
if (sourceArray.count >= 1) {
//AppStore内最新App的版本号
NSDictionary *sourceDict = sourceArray[0];
NSString *newVersion = sourceDict[@"version"];
if ([self judgeNewVersion:newVersion withOldVersion:appVersion])
{
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示:\n您的App不是最新版本,请问是否更新" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"暂不更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// [alertVc dismissViewControllerAnimated:YES completion:nil];
}];
[alertVc addAction:action1];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"去更新" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
//跳转到AppStore,该App下载界面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:sourceDict[@"trackViewUrl"]]];
}];
[alertVc addAction:action2];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:alertVc animated:YES completion:nil];
}
}
}];
}
//每天进行一次版本判断
- (BOOL)judgeNeedVersionUpdate {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"]
//获取年-月-日
NSString *dateString = [formatter stringFromDate:[NSDate date]];
NSString *currentDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentDate"];
if ([currentDate isEqualToString:dateString]) {
return NO;
}
[[NSUserDefaults standardUserDefaults] setObject:dateString forKey:@"currentDate"];
return YES;
}
//判断当前app版本和AppStore最新app版本大小
- (BOOL)judgeNewVersion:(NSString *)newVersion withOldVersion:(NSString *)oldVersion {
NSArray *newArray = [newVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
NSArray *oldArray = [oldVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
for (NSInteger i = 0; i < newArray.count; i ++) {
if ([newArray[i] integerValue] > [oldArray[i] integerValue]) {
return YES;
} else if ([newArray[i] integerValue] < [oldArray[i] integerValue]) {
return NO;
} els { }
}
return NO;
}