ios 实现版本更新检查
来源:互联网 发布:2016淘宝彩票是真的吗 编辑:程序博客网 时间:2024/05/17 21:07
/*http://www.cnblogs.com/weilaikeji/p/3331772.html
第一步: 根据应用名称搜索应用,然后根据应用绑定的ID在结果中筛选出我们要找的应用,并取出应用的AppID
*/
- (void)getAppID {
processView = [[UIProcessViewalloc]initWithFrame:self.view.framewithText:@"检测中..."];
[processView startAnimating];
[self.view addSubview: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"]];
}
}
- ios 实现版本更新检查
- ios 实现版本更新检查
- ios 实现版本更新检查
- ios检查版本更新
- ios检查版本更新
- IOS 版本检查更新
- ios检查版本更新
- ios检查版本更新
- ios检查版本更新
- ios检查版本更新
- iOS检查版本更新
- IOS 检查版本更新
- IOS 检查版本更新
- iOS 版本检查更新
- ios检查版本更新
- IOS检查版本更新
- ios版本检查更新
- iOS自定义版本更新检查
- Android版本百度地图开发(四)——定位
- 单片机脚本语言-移植lua到stm32-MDK
- style、currentStyle、getComputedStyle区别介绍
- Inheritance vs Composition
- Mes系统批次管理功能
- ios 实现版本更新检查
- android与javascript交互调用
- Android版本百度地图开发(五)——覆盖物
- Matlab与C++接口与混合编程讨论小结
- python实现单例模式__init__ __new__区别
- ROI区域图像叠加&初级图像混合
- perl学习笔记一----变量
- html5标签
- 黑马程序员_交通管理系统学习总结