1.对于在app store上面的版本更新
//
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];
NSLog(@"currentVersion = %@",currentVersion); //本地的版本号
NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",kAPPID];//获取app store版本号
[ZHSyncHttpNetworkRequest request:url postDataArray:nil completeBlock:^(NSData *data) { //数据获取(自己定义的类)加解析
NSString *results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
id dict = [results JSONValue];
NSArray *resultArray = [dict valueForKeyPath:@"results"];
if ([resultArray count] > 0) {
NSDictionary *contentDic = [resultArray objectAtIndex:0];
NSString *lastVersion = [contentDic valueForKeyPath:@"version"];
//NSString *trackUrl = [contentDic valueForKeyPath:@"trackViewUrl"];
if (![currentVersion isEqualToString:lastVersion]) {//版本不同 两版本号对比
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"发现新版本,是否现在更新" delegate:self cancelButtonTitle:nil otherButtonTitles:@"马上更新",@"稍后再说", nil];
alertView.tag = 1001;
[alertView show];
}else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前版本是最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
alertView.tag = 1002;
[alertView show];
}
}
} errorBlock:^(NSError *error) {
NSLog(@"request failed in 版本更新");
}];
#pragma mark UIAlertView delegate ---代理方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag ==1001) {
if (buttonIndex == 0) {
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:[NSStringstringWithFormat:@"https://itunes.apple.com/app/id%@",kAPPID]]];//前往更新
}
}
}
2.当然我们一般用的是此种来自 app store上的app下载,但是为了能方便统计来自多种渠道的版本更新我们一般采用umeng统计来进行检测版本更新。
(1)首先导入sdk :libMobClickLibrary.a和MobClick.h
(2)导入framework:libz.1.2.5.dylib
(3)在ZHAppDelegate.m中 #import "MobClick.h"然后在
application: didFinishLaunchingWithOptions:方法中将
[MobClickstartWithAppkey:@"umengKey"]; //umengKey是自己在官网申请的
[MobClick checkUpdate]; //通过查看文档可以查看mobClick类里面给我们封装好了很多的方法
版本更新检查