首先获取当前使用的版本号。代码如下
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
CFShow(infoDic);
NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];
再获取最新版本信息。
这里有很多方法,最简单的一个方法就是服务器给个接口返回最新版本信息。
或者从app store上查询,可以获取到app的作者,连接,版本等。
根据 app 的 id 来查找:
http://itunes.apple.com/lookup?id=你的应用程序的ID,获得数据解析出版本号。通过下面代码一对比。是最后版本不同于当前版本就更新,否则没响应!
if (![lastVersion isEqualToString:currentVersion]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"检测到新版本" delegate:self cancelButtonTitle:@"暂不更新" otherButtonTitles:@"更新", nil];
alert.tag = 9999;
[alert show];
}
else
{ }
}
最后附上跳转更新页面代码。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==9999) {
if (buttonIndex==1) {
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com"];
[[UIApplication sharedApplication]openURL:url];
}
}}
讲道理,苹果官方是拒绝app检测更新的~!但并非没有app仍然带此功能!稍作处理还是能过审核的。自己去想办法吧,很简单