IOS检查版本更新
2016-10-08 15:36
351 查看
iOS的版本号, 一个叫做Version, 一个叫做Build.
获得Version ,
获得build号:
// 以下方法
先获取最新的版本号
再获取当前软件的版本号
最后进行比较
获得Version ,
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
获得build号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
// 以下方法
先获取最新的版本号
再获取当前软件的版本号
最后进行比较
- (void)checkVersionUpdate{ //同步请求 JSON方法获取数据 NSError *error; NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", kAppId]; NSURL *url = [NSURL URLWithString:urlStr]; NSURLRequest *resquest = [NSURLRequest requestWithURL:url]; NSData *response = [NSURLConnection sendSynchronousRequest:resquest returningResponse:nil error:nil]; NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; if (error) { DLog(@"error: = %@", [error description]); return ; } NSArray *resultArray = [appInfoDic objectForKey:@"results"]; if (![resultArray count]) { DLog(@"error: resultArray == nil"); return; } NSDictionary *infoDic = [resultArray objectAtIndex:0]; NSString *lastVersion = [infoDic objectForKey:@"version"]; NSString *trackViewUrl = [infoDic objectForKey:@"trackViewUrl"]; NSString *trackName = [infoDic objectForKey:@"trackName"]; //获取此应用的版本号 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDict objectForKey:@" CFBundleShortVersionString"]; double doubleCurrentVersion = [currentVersion doubleValue]; double doubleUpdateVersion = [lastVersion doubleValue]; //比较 NSString *titleStr = [NSString stringWithFormat:@"检查更新:%@", trackName]; if (doubleCurrentVersio 4000 n < doubleUpdateVersion) { NSString *messagestr = [NSString stringWithFormat:@"发现新版本:%@, 是否升级?", lastVersion]; UIAlertView *alter = [[UIAlertView alloc] initWithTitle:titleStr message:messagestr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"升级", nil]; alter.tag = [kAppId intValue]; [alter show]; }else{ UIAlertView *alter = [[UIAlertView alloc] initWithTitle:titleStr message:@"暂无新版本"delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil]; alter.tag = [kAppId intValue]+1; [alter show]; } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (alertView.tag == [kAppId intValue]) { if (buttonIndex == 1) { //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:_trackViewUrl]]; } } }
相关文章推荐
- ios 使用ASIHTTPRequest来检查版本更新
- iOS 检查app版本更新操作
- IOS应用版本更新如果保留检查更新入口审核时将被拒绝
- iOS自定义版本更新检查
- ios 实现版本更新检查
- ios检查版本更新
- iOS学习笔记18- iOS检查版本更新
- iOS 检查app版本是否要更新 ---站在巨人的肩膀上
- iOS检查版本更新
- ios 实现版本更新检查
- iOS 版本更新检查
- ios 检查版本更新
- iOS开发007 苹果appStore检查版本更新与从app里引导跳到appstore评论页面
- ios检查版本更新
- iOS检查版本更新、APPStore更新地址和评价地址
- ios 实现版本更新检查
- ios检查版本更新
- IOS 检查版本更新
- iOS开发之检查APP版本更新
- iOS —— 检查版本更新