1、獲取App Store版本信息
// 1皇筛、填寫自己App的ID
NSString * strurl = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=1491881948"];//替換為自己App的ID
NSURLSession *session=[NSURLSession sharedSession];
NSURL *url = [NSURL URLWithString:strurl];
//2.創(chuàng)建可變的請(qǐng)求對(duì)象
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error){
//4.解析數(shù)據(jù)
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSArray * results = dict[@"results"];
NSDictionary * dic = results.firstObject;
NSString * lineVersion = dic[@"version"];//版本號(hào)
NSString * releaseNotes = dic[@"releaseNotes"];//更新說明
NSString * trackViewUrl = dic[@"trackViewUrl"];//鏈接
DSLog(@"App store版本號(hào):%@",lineVersion);
DSLog(@"更新說明:%@",releaseNotes);
DSLog(@"App下載鏈接:%@",trackViewUrl);
// 5臭杰、獲取本地版本
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
// 本地app版本
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
// 6味赃、比較版本信息
if ([lineVersion floatValue] > [app_Version floatValue]) {
// 7女蜈、回到主線程進(jìn)行后續(xù)操作
dispatch_async(dispatch_get_main_queue(), ^{
[self setGengxinUI];
});
DSLog(@"^^%@",app_Version);
}else{
// 7怜跑、回到主線程進(jìn)行后續(xù)操作
dispatch_async(dispatch_get_main_queue(), ^{
[SOSVC SOSToolTipShow:@"提示" message:@"已是最新版本" cancelTitle:@"確定" otherTitle:nil];
});
}
}];
//3.執(zhí)行任務(wù)
[dataTask resume];
2、跳轉(zhuǎn)App Store和應(yīng)用內(nèi)下載更新app兩種方式
- 跳轉(zhuǎn)App Store 下載
// id99637153*是app的唯一id锥腻,對(duì)應(yīng)上文的trackViewUrl
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/%E4%B8%9C%E6%96%B9%E7%BE%8E%E9%A3%9F/id99637153*?mt=8"] options:@{} completionHandler:nil];
2.應(yīng)用內(nèi)更新下載
導(dǎo)入頭文件: #import <StoreKit/StoreKit.h>
準(zhǔn)守協(xié)議:<SKStoreProductViewControllerDelegate>
1.實(shí)現(xiàn)代理SKStoreProductViewControllerDelegate
SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init];
storeProductViewContorller.delegate = self;
[storeProductViewContorller loadProductWithParameters: @{SKStoreProductParameterITunesItemIdentifier : @"996371534"} completionBlock:^(BOOL result, NSError *error) {
if(error){
NSLog(@"錯(cuò)誤%@",error);
}else{
//應(yīng)用界面
[self.window.rootViewController presentViewController:storeProductViewContorller animated:YES completion:nil];
}
}];
//實(shí)現(xiàn)取消協(xié)議
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
[self disMiss];
}
原文鏈接:http://www.reibang.com/p/d2dd7d2f37b2
鏈接:http://www.reibang.com/p/0190e5234af2