ios 实现版本更新检查
来源:互联网 发布:电信网络代理免费 编辑:程序博客网 时间:2024/06/09 04:06
/*
第一步: 根据应用名称搜索应用,然后根据应用绑定的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 = [[UIAlertViewalloc] initWithTitle:@"提示"message: @"有新的版本可供下载" delegate:selfcancelButtonTitle:@"下次再说" 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 版本检查更新
- ios检查版本更新
- ios检查版本更新
- ios检查版本更新
- ios检查版本更新
- iOS检查版本更新
- IOS 检查版本更新
- IOS 检查版本更新
- iOS 版本检查更新
- ios检查版本更新
- IOS检查版本更新
- ios版本检查更新
- iOS自定义版本更新检查
- 几个提高网站权重的方法
- jsp和servlet的区别
- cocos2dx v3.0 正式版 搭建环境 创建项目 运行到android
- connect-flash 模块使用
- hdu 4496 D-City(并查集)
- ios 实现版本更新检查
- python的多态性学习思考1
- IDisposable 在C#中的作用
- 手机传感器及交互方式总结
- 南阳理工OJ_题目71 独木舟上的旅行
- NEFU 642 Monkey(DP)
- 从零开始学OpenGLES开发——第一章
- 解析nginx负载均衡
- umlの用例图