注:这里网络请求用的是第三方框架:SVHTTPRequest

/*

第一步: 根据应用名称搜索应用,然后根据应用绑定的ID在结果中筛选出我们要找的应用,并取出应用的AppID

*/

- (void)getAppID {

processView  = [[UIProcessViewalloc]initWithFrame:self.view.framewithText:@"检测中..."];

[processViewstartAnimating];

[self.viewaddSubview:processView];

[SVHTTPRequestPOST:@"http://itunes.apple.com/search"

parameters:[[NSDictionaryalloc] initWithObjectsAndKeys:APP_NAME,@"term",@"software",@"entity",nil]

completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {

if (!error&&[urlResponse statusCode]==200) {

NSData *data = (NSData *)response;

id res = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];

NSLog(@"res.class==%@",[res class]);

NSLog(@"res == %@",res);

NSLog(@"results class == %@",[[res objectForKey:@"results"]class]);

NSArray *arr = [res objectForKey:@"results"];

for (id config in arr)

{

NSString *bundle_id = [config valueForKey:@"bundleId"];

if ([bundle_id isEqualToString:APP_BUNDLE_IDENTIFIER]) {

[processView stopAnimating];

app_id  = [config valueForKey:@"trackId"];

updateURL = [config valueForKey:@"trackViewUrl"];

NSString *app_Name = [config valueForKey:@"trackName"];

NSString *version = [config valueForKey:@"version"];

NSLog(@"app_id == %@,app_Name == %@,version == %@",app_id,app_Name,version);

[self checkUpdate:version];

}

}

} else {

[processView stopAnimating];

[CTCommonUtilsshowAlertViewOnView:self.viewwithText:@"检测失败,当前无网络连接!"];

}

}];

}

/*

第二步:通过比较从App Store获取的应用版本与当前程序中设定的版本是否一致,然后判断版本是否有更新

*/

- (void)checkUpdate:(NSString *)versionFromAppStroe {

NSDictionary *infoDict = [[NSBundlemainBundle] infoDictionary];

NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];

NSLog(@"nowVersion == %@",nowVersion);

[processViewstopAnimating];

//检查当前版本与appstore的版本是否一致

if (![versionFromAppStroe isEqualToString:nowVersion])

{

UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:@"提示" message: @"有新的版本可供下载" delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles: @"去下载", nil];

[createUserResponseAlert show];

} else {

[CTCommonUtilsshowAlertViewOnView:self.viewwithText:@"暂无新版本"];

}

}

#pragma mark - AertView delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if (buttonIndex == 1) {

   //去appstore中更新

//方法一:根据应用的id打开appstore,并跳转到应用下载页面

//NSString *appStoreLink = [NSString stringWithFormat:@"http://itunes.apple.com/cn/app/id%@",app_id];

//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStoreLink]];

//方法二:直接通过获取到的url打开应用在appstore,并跳转到应用下载页面

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:updateURL]];

} else if (buttonIndex == 2) {

//去itunes中更新

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"itms://itunes.apple.com/cn/app/guang-dian-bi-zhi/id511587202?mt=8"]];

}

}

#pragma mark -

ios 实现版本更新检查的更多相关文章

  1. iOS 检测版本更新(02)

    iOS 检测版本更新 如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bu ...

  2. iOS 版本更新检查

    #pragma mark ---------------------------------- #pragma mark -- 检测版本更新 -(void)onCheckVersion { NSDic ...

  3. iOS - Harpy版本更新工具兼容版本第三方库

    Harpy(兼容版) git地址:https://github.com/yangchao0033/Harpy ###(iOS5-9适配版本,基于ArtSabintsev/Harpy v3.4.5) 提 ...

  4. iOS 之 内存检查instrument

    经常听见iOS开发instrument是一个内存检查工具,但是,没想到,它是集成在xcode里面的,而且打开一看,感觉功能非常强大. 打开方式是 product -> profile 头一次运行 ...

  5. iOS检测版本更新

    有时候为了需求,我们需要检测app版本更新今天在这里整合下 //获取当前版本号 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDi ...

  6. iOS软件版本更新思路

    iOS软件更新思路 需要更新版本数组 needUpdateVersions{1.2.61.2.8} 历史版本数组 historyUpdateVersions1.2.41.2.51.2.6 更新数据库1 ...

  7. iOS 检测版本更新

    如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bundle versio ...

  8. 苹果iOS系统下检查第三方APP是否安装及跳转启动

    在iOS系统,使用Url Scheme框架在APP间互相跳转和传递数据,本文只介绍如果检测和跳转. Url Scheme框架 如果你想知道ios设备中是否安装QQ这个软件,我们可以通过一个简单方法判断 ...

  9. iOS开发 如何检查内存泄漏

    本文转载至 http://mobile.51cto.com/iphone-423391.htm 在开发的时候内存泄漏是不可避免的,但是也是我们需要尽量减少的,因为内存泄漏可能会很大程度的影响程序的稳定 ...

随机推荐

  1. Android 热补丁和热修复

    参考: 各大热补丁方案分析和比较 Android App 线上热修复方案 1. Xposed Github地址:https://github.com/rovo89/Xposed 项目描述:Xposed ...

  2. c++ 关于new文件

    new文件用来管理c++的动态内存,这个文件声明了几个全局空间的函数(不是std空间的函数,全局空间的函数调用时是用全局作用域解析符),包括operator new 和operator delete的 ...

  3. BZOJ4127: Abs

    Description 给定一棵树,设计数据结构支持以下操作 1 u v d 表示将路径 (u,v) 加d 2 u v 表示询问路径 (u,v) 上点权绝对值的和 Input 第一行两个整数n和m,表 ...

  4. 实现UITableView循环利用

    tableViewUITableView循环利用 前言 大家都知道UITableView,最经典在于循环利用,这里我自己模仿UITableView循环利用,写了一套自己的TableView实现方案,希 ...

  5. Let It Be - The Beatles - Lyrics

    轉載自 https://www.youtube.com/watch?v=0714IbwC3HA When I find myself in times of trouble, Mother Mary ...

  6. Golang redigo hmset hset 问题

    最近公司项目,换到了golang 下面来开发,遇到了redis存储链表的问题,困扰了我好几天,后面静下心来,好好读了一下源码,发现官方的例子,最终还是羊毛出在羊身上 c, err := dial() ...

  7. Oracle connect by 树查询之三(超详细)

    查找员工编号为7369的领导: 1 SELECT LEVEL,E.* FROM EMP E CONNECT BY PRIOR E.MGR = E.EMPNO START WITH E.EMPNO = ...

  8. C#常用方法集合

    public class Utility:Page { #region 数据转换 /// <summary> /// 返回对象obj的String值,obj为null时返回空值. /// ...

  9. Mybatis一级、二级缓存

      Mybatis一级.二级缓存   一级缓存 首先做一个测试,创建一个mapper配置文件和mapper接口,我这里用了最简单的查询来演示. <mapper namespace="c ...

  10. linux下创建,删除,移动文件命令

    创建文件:touch + filename 删除文件:rm + filename 复制文件:cp + filename + dirname 移动文件:mv + filename + dirname 注 ...