ios 实现版本更新检查
2014-05-01 15:06
483 查看
/*
第一步: 根据应用名称搜索应用,然后根据应用绑定的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 -
第一步: 根据应用名称搜索应用,然后根据应用绑定的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 实现版本更新检查
- ios 实现版本更新检查
- ios 实现版本更新检查
- iOS 项目如何实现版本的更新?
- IOS检查版本更新
- iOS【 APP检查版本更新 】
- ios项目如何实现版本更新?
- iOS跳转到AppStore,AppStore检查版本更新(上线会被拒),跳转到设置界面
- iOS检查版本更新
- ios检查版本更新
- ios检查版本更新
- iOS 【获取 AppStore 的上架信息 - 检查版本更新】
- ios检查版本更新
- iOS检查版本更新,以及获取不到版本信息问题
- IOS 版本检查更新
- ios 检查版本更新
- iOS检查版本更新、APPStore更新地址和评价地址
- iOS学习笔记31—appStore检查版本更新与从app里跳到appstore评论页面
- ios检查版本更新
- IOS 检查版本更新