其实和后天版本号比较,无非就是在后台写段代码,记录版本号,每次更新手动修改版本号。后来我发现一种方法,就是解析plist。因为打包的时候plist里存着版本号:代码如下。
-(void)updateApp{
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://你服务器上plist的地址/Picc.plist"]];
if (dict) {
NSArray* list = [dict objectForKey:@"items"];
NSDictionary* dict2 = [list objectAtIndex:0];
NSDictionary* dict3 = [dict2 objectForKey:@"metadata"];
NSString* newVersion = [dict3 objectForKey:@"bundle-version"];
// NSLog(@"版本号%@",dict4);
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *myVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
if (![newVersion isEqualToString:myVersion]) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"有新版本" delegate:self cancelButtonTitle:@"马上去更新" otherButtonTitles:@"暂不更新", nil];
[alert showWithCompletionHandler:^(NSInteger buttonIndex) {
if (buttonIndex ==0) {
NSLog(@"更新");
NSLog(@"%@",DOWNLOAD);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:DOWNLOAD]];
} else if(buttonIndex ==1){
NSLog(@"不更新");
} }]; } else{
UIAlertView * aler = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您已经是最新版" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[aler show]; } } else{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请检查网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; } }