ios中應用的版本判斷有兩種方法:
1.将你的應用版本号同步在你自己的伺服器上,打開程式後去自己的伺服器擷取版本号和手機上的應用版本号做比較,然後去appstore更新
2.通過url擷取appstore上的最新版本資訊,然後和手機上的程式版本号做比較,判斷是否更新。
最常用的就是方法2,下面講講方法2的實作過程。
第一步是去擷取appstore上你的應用的版本資訊,需要用到的url #define APP_URL @"http://itunes.apple.com/lookup?id=662004496"
//連網擷取appstore 裡軟體的版本号與本地的版本号對比。目前版本号< appstore 裡的版本,提示更新。
[NetWork getWithURL:homeUrl params:nil success:^(NSDictionary * responseObject) {
NSArray *infoArray = [responseObject objectForKey:@"results"];
if (infoArray.count > 0) {
NSDictionary* releaseInfo =[infoArray objectAtIndex:0];
//appstore 版本
NSString* appStoreVersion = [releaseInfo objectForKey:@"version"];
//目前版本
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
if ([currentVersion compare:appStoreVersion]==NSOrderedAscending)
{
self.trackStr=releaseInfo[@"trackViewUrl"];
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"發現新版本" message:@"有新版本了,趕快更新看看吧!" delegate:self cancelButtonTitle:@"稍後再說" otherButtonTitles:@"立即更新", nil];
[alertView show];
}
}
} failure:^(NSError *error) {
}];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==1)
{
NSURL *trackURL=[NSURL URLWithString:self.trackStr];
[[UIApplication sharedApplication]openURL:trackURL];
}
}