注:这里网络请求用的是第三方框架: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. SAD算法在opencv上的实现代码(c++)

    #include <opencv2/opencv.hpp>#include <opencv2/core/core.hpp>#include <opencv2/highgu ...

  2. 利用百度云盘API上传文件至百度云盘

    一.获取Access Token示例 1. 请您将以下HTTP请求直接粘贴到浏览器地址栏内,并按下回车键. https://openapi.baidu.com/oauth/2.0/authorize? ...

  3. Codeforces Testing Round #10 B. Balancer

    水题,只要遍历一遍,不够平均数的,从后面的借,比平均数多的,把多余的数添加到后面即可,注意数据范围 #include <iostream> #include <vector> ...

  4. 【BZOJ】1110: [POI2007]砝码Odw

    题意 给定\(n\)个砝码和\(m(1 \le n, m \le 100000)\)个背包\((1 \le n_i, m_i \le 1000000000)\),保证对于任意两个砝码都有一个是另一个的 ...

  5. URAL 1427. SMS(DP+单调队列)

    题目链接 我用的比较传统的办法...单调队列优化了一下,写的有点搓,不管怎样过了...两个单调队列,存两个东西,预处理一个标记数组存... #include <iostream> #inc ...

  6. Unity5.x版本AssetBundle加载研究

    之前说了 “Unity5.x版本AssetBundle打包研究”,没看过的请先看一下:http://www.shihuanjue.com/?p=57 再来看本文,有一定的连接性. 先梳理一下思路: 要 ...

  7. git 常用

    1. 打印 git 的 log 日志:git log --after="2016-05-05" --no-merges 2. 可以通过在本地建立分支,来添加自己的注释.上传公司的代 ...

  8. The Beatles-Hey Jude

    轉載自 https://www.youtube.com/watch?v=V3jCYm_QGZQ Hey Jude, don't make it bad.Take a sad song and make ...

  9. Android studio 一个项目中添加两个module遇到的bug

    1.在一个Android studio中,我添加了一个模块,然后就是各种bug 找到到R 是在module 名上面 右键 Make Module '模块名' 经过各种google 的时候发现了 htt ...

  10. 快排java实现

    package sort; public class QuickSort { public static final int cutoff = 3; /** * insertion sort * * ...