ios检测新版本方法并更新
2015-02-02 16:32
197 查看
//检查版本更新
//APPLEID 是提交到appstore的应用id
-(void)onCheckVersion
{
NSDictionary *infoDic = [[NSBundlemainBundle]
infoDictionary];
NSString *currentVersion = [infoDic
objectForKey:@"CFBundleVersion"]; 获取本地版本号
NSString * URL = [NSStringstringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",APPLEID];
//请求itunes.apple应用版本信息,
NSMutableURLRequest *request = [[NSMutableURLRequestalloc]
init];
[requestsetURL:[NSURLURLWithString:URL]];
[requestsetHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse =
nil;
NSError *error =
nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request
returningResponse:&urlResponse
error:&error];
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData
options:kNilOptionserror:&error]; //取回的数据是json格式,必须进行解析
NSArray *infoArray = [dic
objectForKey:@"results"];
if ([infoArray
count]) {
NSDictionary *releaseInfo = [infoArray
objectAtIndex:0];
NSString *lastVersion = [releaseInfo
objectForKey:@"version"]; //获取到最新版本号
//如果applestore最新版本号和本地版本不同,提醒用户更新
if (![lastVersion
isEqualToString:currentVersion]) {
//trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"暂不更新"otherButtonTitles:@"更新",nil];
alert.tag =10000;
[alertshow];
}
//如果相同,提醒用户已是最新版本
else
{
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"更新"message:@"此版本为最新版本"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
[alertshow];
}
}
}
}
//alart回调方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//去appstore进行下载
else
if (alertView.tag ==10000){
if (buttonIndex==1) {
NSURL *url = [NSURLURLWithString:[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/wifi-xiao-guan-jia/id%@",APPLEID]];
//拼接下载地址字符串
[[UIApplicationsharedApplication]openURL:url]; //打开app所在网页
}
}
}
//APPLEID 是提交到appstore的应用id
-(void)onCheckVersion
{
NSDictionary *infoDic = [[NSBundlemainBundle]
infoDictionary];
NSString *currentVersion = [infoDic
objectForKey:@"CFBundleVersion"]; 获取本地版本号
NSString * URL = [NSStringstringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",APPLEID];
//请求itunes.apple应用版本信息,
NSMutableURLRequest *request = [[NSMutableURLRequestalloc]
init];
[requestsetURL:[NSURLURLWithString:URL]];
[requestsetHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse =
nil;
NSError *error =
nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request
returningResponse:&urlResponse
error:&error];
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData
options:kNilOptionserror:&error]; //取回的数据是json格式,必须进行解析
NSArray *infoArray = [dic
objectForKey:@"results"];
if ([infoArray
count]) {
NSDictionary *releaseInfo = [infoArray
objectAtIndex:0];
NSString *lastVersion = [releaseInfo
objectForKey:@"version"]; //获取到最新版本号
//如果applestore最新版本号和本地版本不同,提醒用户更新
if (![lastVersion
isEqualToString:currentVersion]) {
//trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"暂不更新"otherButtonTitles:@"更新",nil];
alert.tag =10000;
[alertshow];
}
//如果相同,提醒用户已是最新版本
else
{
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"更新"message:@"此版本为最新版本"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
[alertshow];
}
}
}
}
//alart回调方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//去appstore进行下载
else
if (alertView.tag ==10000){
if (buttonIndex==1) {
NSURL *url = [NSURLURLWithString:[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/wifi-xiao-guan-jia/id%@",APPLEID]];
//拼接下载地址字符串
[[UIApplicationsharedApplication]openURL:url]; //打开app所在网页
}
}
}
相关文章推荐
- iOS 版本检测更新方法
- iOS App 的版本更新检测的方法
- Android应用检测并下载更新新版本的方法
- iOS App 的版本更新检测的方法
- iOS 提供一种检测新版本的方法
- iOS开发常见错误及其解决方法(长期更新)
- android检测新版本并下载安装的方法
- iOS版本更新的方法
- iOS下图像颜色检测、颜色匹配的解决方法
- iOS应用检查更新的最优方法
- IOS检测版本更新(***为app id)
- 【iOS-iap防护】验证用户付费收据!拒绝iap Cracker!拒绝iap Free!让iphone越狱用户无从下手!【2012年5月2日更新防护iap Free的方法】
- 【iOS-iap防护】验证用户付费收据!拒绝iap Cracker!拒绝iap Free!让iphone越狱用户无从下手!【2012年5月2日更新防护iap Free的方法】
- 转载 -- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- IOS检查更新的方法
- iOS应用检查更新的最优方法
- iOS版本更新的方法
- 谈谈iOS下图像颜色检测、颜色匹配的解决方法
- (iPhone/iPad开发)iOS应用检查更新的最优方法