ios 版本更新
2015-08-03 16:26
465 查看
NSDictionary *infoDict = [[NSBundle
mainBundle] infoDictionary];
NSString *currentVersion = [infoDict
objectForKey:@"CFBundleVersion"];
double doubleCurrentVersion = [currentVersion
doubleValue];
NSURLRequest *req = [NSURLRequest
requestWithURL:[NSURL
URLWithString:@"http://itunes.apple.com/lookup?id=你的appid"]];
AFHTTPRequestOperation *request = [[AFHTTPRequestOperation
alloc] initWithRequest:req];
[request setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,
id responseObject) {
NSString *str=[[NSString
alloc] initWithData:responseObject
encoding:NSUTF8StringEncoding];
NSDictionary *jsonData = [NSJSONSerialization
JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
options:NSJSONReadingMutableContainers
error:nil];
NSLog(@"%@",jsonData);
NSArray *infoArray = [jsonData
objectForKey:@"results"];
if (infoArray.count!=0) {
NSDictionary *releaseInfo = [infoArray
objectAtIndex:0];
NSString *latestVersion = [releaseInfo
objectForKey:@"version"];
NSString *trackViewUrl = [releaseInfo
objectForKey:@"trackViewUrl"];
_updateUrl = trackViewUrl;
double updateVersion = [latestVersion
doubleValue];
if (updateVersion > doubleCurrentVersion) {
UIAlertView *alertd = [[UIAlertView
alloc] initWithTitle:@"温馨提示"
message:@"检测到有新版本,立即前往更新?"
delegate:self
cancelButtonTitle:@"暂不更新"
otherButtonTitles:@"立即前往",
nil];
alertd.tag =
110;
[alertd show];
}else
{
// [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil] show];
}
}else{
// [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil] show];
}
} failure:^(AFHTTPRequestOperation *operation,
NSError *error) {
// [self errorActionWith:error];
}];
[request start];
}
mainBundle] infoDictionary];
NSString *currentVersion = [infoDict
objectForKey:@"CFBundleVersion"];
double doubleCurrentVersion = [currentVersion
doubleValue];
NSURLRequest *req = [NSURLRequest
requestWithURL:[NSURL
URLWithString:@"http://itunes.apple.com/lookup?id=你的appid"]];
AFHTTPRequestOperation *request = [[AFHTTPRequestOperation
alloc] initWithRequest:req];
[request setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,
id responseObject) {
NSString *str=[[NSString
alloc] initWithData:responseObject
encoding:NSUTF8StringEncoding];
NSDictionary *jsonData = [NSJSONSerialization
JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
options:NSJSONReadingMutableContainers
error:nil];
NSLog(@"%@",jsonData);
NSArray *infoArray = [jsonData
objectForKey:@"results"];
if (infoArray.count!=0) {
NSDictionary *releaseInfo = [infoArray
objectAtIndex:0];
NSString *latestVersion = [releaseInfo
objectForKey:@"version"];
NSString *trackViewUrl = [releaseInfo
objectForKey:@"trackViewUrl"];
_updateUrl = trackViewUrl;
double updateVersion = [latestVersion
doubleValue];
if (updateVersion > doubleCurrentVersion) {
UIAlertView *alertd = [[UIAlertView
alloc] initWithTitle:@"温馨提示"
message:@"检测到有新版本,立即前往更新?"
delegate:self
cancelButtonTitle:@"暂不更新"
otherButtonTitles:@"立即前往",
nil];
alertd.tag =
110;
[alertd show];
}else
{
// [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil] show];
}
}else{
// [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil] show];
}
} failure:^(AFHTTPRequestOperation *operation,
NSError *error) {
// [self errorActionWith:error];
}];
[request start];
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 初级:如何在终端及图形界面中更新 Ubuntu
- 必须会的SQL语句(四) 数据删除和更新
- bat+xcopy实现只复制比目标文件更新的文件
- 使用 TOP 子句限制UPDATE 语句更新的数据
- 与MSSQL对比学习MYSQL的心得(八)--插入 更新 删除
- php使用COPY函数更新配置文件的方法
- C#在子线程中更新窗口部件的写法
- Shell脚本中实现更新PHP5
- Android实现检查并下载APK更新、安装APK及获取网络信息的方法
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- javascript的动态加载、缓存、更新以及复用(一)