- didfinishlauch appdelegate 中
// 01 gzz022 版本更新
[self VersionButton];
//02 gzz0222 提示自动更新
-(void)VersionButton{
NSString *string=[NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://itunes.apple.com/lookup?id=1079728205"] encoding:NSUTF8StringEncoding error:nil];
if (string!=nil &&[string length]>0&&[string rangeOfString:@"version"].length==7 ) {
[self checkUpAppUpdate:string];
}
}
//03 gzz0222
-(void)checkUpAppUpdate:(NSString *)appInfo{
//获取当前版本
// NSString *version=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];//CFBundleShortVersionString
NSString *version=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];//CFBundleShortVersionString
NSString *appInfo1=[appInfo substringFromIndex:[appInfo rangeOfString:@""version":"].location+10];
appInfo1=[[appInfo1 substringToIndex:[appInfo1 rangeOfString:@","].location]stringByReplacingOccurrencesOfString:@""" withString:@""];
//判断,如果当前版本与发布的版本不相同,则进入更新.如果相等,那么当前版本就是最新版本
// NSString *ver2=@"2.0";
if (![appInfo1 isEqualToString:version]) {
NSLog(@"%@ 新版本,%@当前版本",appInfo1,version);
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:[NSString stringWithFormat:@"新版本 %@ 已发布!",appInfo1] delegate:self.class cancelButtonTitle:@"稍后更新" otherButtonTitles:nil, nil];
alert.delegate=self;
[alert addButtonWithTitle:@"前往更新"];
[alert show];
alert.tag=20019;
}else{
// UIAlertView *alll= [[UIAlertView alloc]initWithTitle:nil message:@"已是最高版本!" delegate:self.class cancelButtonTitle:@"知道啦!" otherButtonTitles:nil ,nil];
//
// [alll show];
}
}
//alertview代理
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (alertView.tag==20019&&buttonIndex==1) {
NSString *strUrl=[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/gan-dan-xiang-zhao/id1079728205?mt=8"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:strUrl]];
}
}