检测版本更新
来源:互联网 发布:雅思自学 知乎 编辑:程序博客网 时间:2024/06/16 11:33
- (BOOL)checkHaveNewVersion_Func
{
[MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];
__blockBOOL bHaveNewVersionFlag = FALSE; // 有新版本标志
// // 首先取得本地程序版本号
NSDictionary *infoDic = [[NSBundlemainBundle] infoDictionary];
//这个地方 一定要注意,因为appstore里返回的版本信息最前面加了个V 所以这个地方必须也加个
NSString *localVersion = [NSStringstringWithFormat:@"V%@",[infoDicobjectForKey:@"CFBundleShortVersionString"]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
// 发送检测版本数据到app store
NSString *URL = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APPID];
NSMutableURLRequest *request = [[NSMutableURLRequestalloc] init];
[request setURL:[NSURLURLWithString:URL]];
[request setHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse =nil;
__blockNSError *error = nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request returningResponse:&urlResponse error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
//IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中: json4种方式用法及比较http://blog.csdn.net/enuola/article/details/7903632
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData options:NSJSONReadingMutableLeaveserror:&error];
// 解析数据
NSArray *infoArray = [dicobjectForKey:@"results"];
if (0 < [infoArraycount]) {
NSDictionary *releaseInfo = [infoArrayobjectAtIndex:0];
NSString *appStoreVersion = [releaseInfoobjectForKey:@"version"];
// appstore版本比本地版本高,则可更新
if (NSOrderedAscending == [localVersioncompare:appStoreVersion]) { // 有新版本
bHaveNewVersionFlag = YES;
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:MY_Local_Str(@"温馨提示")message:MY_Local_Str(@"已有新版本,是否前去更新")delegate:selfcancelButtonTitle:MY_Local_Str(@"暂不更新")otherButtonTitles:MY_Local_Str(@"更新"),nil];
[alertView show];
} else {// 无新版本
bHaveNewVersionFlag = NO;
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
[GlobalClasspromptWithString:@"当前程序已是最新版本"onView:self.view];
}
} else {
bHaveNewVersionFlag = NO;
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
[GlobalClasspromptWithString:@"当前程序已是最新版本"onView:self.view];
}
});
});
return bHaveNewVersionFlag;
}
- 版本更新检测
- iOS 检测版本更新
- Android 检测版本更新
- iOS 检测版本更新
- IOS检测版本更新
- iOS检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- IOS 版本更新检测
- iOS 检测版本更新
- iOS 检测版本更新
- iOS --检测更新版本
- 检测版本更新
- ios检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- 5种编写网页的软件介绍(四)
- 求出平均成绩,最高分和最低分
- 程序:从标准输入C源代码,验证所有的“{”和“}”都是成对出现的
- Nested Loops Join、Hash join、Merge Sort Join三大经典表连接浅谈(笔记)
- Tarjan算法
- 检测版本更新
- [总结]RTMP流媒体技术零基础学习方法
- 算法训练 K好数 (动态规划)
- 图像地图
- 从原字符串中得到一个字符串
- OC方法和文件编译(总结的很好拿来用了)
- js树形插件fancytree的使用
- 温故知新--Servlet(六)--HttpServletResponse对象
- 高精度大整数类