admin 管理员组文章数量: 1184232
iOS检查更新的方法
一些应用要检查更新,基本思路是获取当前版本号,然后解析url里面的版本号,并讲2者进行对比判断。代码如下:
- (IBAction)button:(id)sender {
NSString * string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@”
“] encoding:NSUTF8StringEncoding error:nil];
if (string != nil &&[string length]>0 &&[string rangeOfString:@”Version”].length == 7) {
[self Postpath:string];
}
}
// 解析url,获取当前在服务器上面的版本号
- (void)Postpath:(NSString *)appInfo{
//获取本地的版本号
NSString * version = [[[NSBundle mainBundle]infoDictionary]objectForKey:@”CFBundleShortVersionString”];
//截取出url上面的版本号
NSString * appInfo1 = [appInfo substringFromIndex:[appInfo rangeOfString:@”\”version\”:”].location+10];
appInfo1 = [[[appInfo1 substringToIndex:[appInfo rangeOfString:@”,”].location]stringByReplacingOccurrencesOfString:@”\”” withString:@”“]componentsSeparatedByString:@”,”][0];
if (![appInfo1 isEqualToString:version]) {
UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@”提示” message:@”发现新版本,需要升级么?” delegate:self cancelButtonTitle:@”确定” otherButtonTitles:@”取消”, nil];
alert.tag = 999;
[alert show];
}else{
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@”提示” message:@”已经是最新版本了” cancelButtonTitle:@”确定” otherButtonTitles:nil];
[alert show];
}
}
//alertView的代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==999){
if(buttonIndex==0) {
[self updataApp];
}
else{
[alertView dismissWithClickedButtonIndex:1 animated:YES];
};
}
}
//更新app
-(void)updataApp{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”
“]];
}
在需要的时候把地址更换一下就可以了
版权声明:本文标题:iOS与Flash:应用更新,让体验更上一层楼 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1773220498a3559546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论