APP检查升级的实现
#define KStoreAPPID @"972057043"
#pragma mark - 检测更新
- (void)checkVersion {
/*
result = {
resultCount = 0;
results = (
);
}
*/
__block NSString *newVersion = nil;
//NSString *appID = @"972057043";
NSString *urlString = [NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",KStoreAPPID];
[LFMyDataService requestWithAFURL:urlString httpMethod:@"GET" params:nil data:nil complection:^(id result) {
NSLog(@"result = %@",result);
NSArray *results = result[@"results"];
if (results.count <= 0) {
NSLog(@"___初始(第一个)版本__");
}else {
for (id config in results) {
newVersion = [config objectForKey:@"version"];
NSLog(@"通过App Store获得的版本是:%@",newVersion);
}
}
//本地获取版本号
NSString *localVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSString *msg = [NSString stringWithFormat:@"你当前版本是:%@,发现新版本:%@。是否下载最新版本", localVersion, newVersion];
if ([newVersion floatValue] > [localVersion floatValue]) {
UIAlertView *updateAlert = [[UIAlertView alloc] initWithTitle:@"升级提示" message:msg delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles:@"现在升级", nil];
updateAlert.tag = 10000;
[updateAlert show];
}
}];
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == 10000) {
//软件需要更新提示
if (buttonIndex == 1) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8", KStoreAPPID]];
[[UIApplication sharedApplication] openURL:url];
/*
//打开itunes 方法二:此方法总提示“无法连接到itunes” 不推荐使用
//NSString *itunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%i&mt=8";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%@&mt=8", KStoreAPPID]];
[[UIApplication sharedApplication] openURL:url];
*/
}
}
}
如果想知道网络请求AppStore时返回的信息可以打开这个链接:http://itunes.apple.com/cn/lookup?id=465039730