//检查版本更新
//APPLEID 是提交到appstore的应用id
-(void)onCheckVersion
{
//获取本地版本号
NSDictionary *infoDic = [[NSBundlemainBundle]infoDictionary];
NSString *currentVersion = [infoDicobjectForKey:@"CFBundleVersion"];
NSString * URL = [NSStringstringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",APPLEID]; //请求itunes.apple应用版本信息,
NSMutableURLRequest *request = [[NSMutableURLRequestalloc]init];
[requestsetURL:[NSURLURLWithString:URL]];
[requestsetHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse =nil;
NSError *error =nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:&urlResponseerror:&error];
NSDictionary *dic = [NSJSONSerializationJSONObject WithData:recervedData options:kNilOptionserror:&error]; //取回的数据是json格式,必须进行解析
NSArray *infoArray = [dicobjectForKey:@"results"];
if ([infoArraycount]) {
NSDictionary *releaseInfo = [infoArrayobjectAtIndex:0];
NSString *lastVersion = [releaseInfoobjectForKey:@"version"]; //获取到最新版本号
//如果applestore最新版本号和本地版本不同,提醒用户更新
if (![lastVersionisEqualToString:currentVersion]) {
//trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"暂不更新"otherButtonTitles:@"更新",nil];
alert.tag =10000;
[alertshow];
}
//如果相同,提醒用户已是最新版本
else
{
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"更新"message:@"此版本为最新版本"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
[alertshow];
}
}
}
}
//alart回调方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//去appstore进行下载
elseif (alertView.tag ==10000){
if (buttonIndex==1) {
NSURL *url = [NSURLURLWithString:[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/wifi-xiao-guan-jia/id%@",APPLEID]]; //拼接下载地址字符串
[[UIApplicationsharedApplication]openURL:url]; //打开app所在网页
}
}
}