http://www.cnblogs.com/jys509/p/5390505.html從這邊看到的
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self hsUpdateApp];
}
-(void)hsUpdateApp
{
//2先獲取當(dāng)前工程項(xiàng)目版本號
NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
NSString *currentVersion=infoDic[@"CFBundleShortVersionString"];
//3從網(wǎng)絡(luò)獲取appStore版本號
NSError *error;
NSData *response = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",APPID]]] returningResponse:nil error:nil];
if (response == nil) {
NSLog(@"你沒有連接網(wǎng)絡(luò)哦");
return;
}
NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
if (error) {
NSLog(@"hsUpdateAppError:%@",error);
return;
}
NSArray *array = appInfoDic[@"results"];
NSDictionary *dic = array[0];
NSString *appStoreVersion = dic[@"version"];
//打印版本號
NSLog(@"當(dāng)前版本號:%@\n商店版本號:%@",currentVersion,appStoreVersion);
//4當(dāng)前版本號小于商店版本號,就更新
if([currentVersion compare:appStoreVersion options:NSNumericSearch] == NSOrderedAscending)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本有更新" message:[NSString stringWithFormat:@"檢測到新版本(%@),是否更新?",appStoreVersion] delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
[alert show];
}else{
NSLog(@"版本號好像比商店大噢!檢測到不需要更新");
}
}
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//5實(shí)現(xiàn)跳轉(zhuǎn)到應(yīng)用商店進(jìn)行更新
if(buttonIndex==1)
{
//6此處加入應(yīng)用在app store的地址,方便用戶去更新,一種實(shí)現(xiàn)方式如下:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@", APPID]];
[[UIApplication sharedApplication] openURL:url];
}
}
用于記錄下以后可能用到
但是現(xiàn)在的appstore不會通過這樣的功能
所以你只能與服務(wù)器的版本相互匹配.來實(shí)現(xiàn)提醒更新