1. 应用程序已经放在appstore时更新比较简单,就是比较版本号,当发现版本高于当前版本时,就访问appstore应用程序所在位置,让用户决定是否更新。
使用xml文件保存版本信息,updateInfo_ios.xml内容如下
<?xml version="1.0" encoding="UTF-8"?>
<updateInfo>
<version>1.0.1</version>
<description>软件升级!!!</description>
<path>itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=524298520</path>
</updateInfo>
其中,version是新的版本号,path是应用程序在appstore的地址
使用TBXML读取从服务端请求来的xml文件内容,这里请求回来的是string类型
TBXML *xml = [[TBXML alloc] initWithXMLString:jsonString error:nil];
TBXMLElement *update = xml.rootXMLElement;
if (update == nil) {
[Tool ToastNotification:@"获取版本信息错误" andView:self.view andLoading:NO andIsBottom:NO];
return;
}
TBXMLElement *versionXML = [TBXML childElementNamed:@"version" parentElement:update];
if (versionXML == nil) {
[Tool ToastNotification:@"获取版本信息错误" andView:self.view andLoading:NO andIsBottom:NO];
return;
}
TBXMLElement *pathXML = [TBXML childElementNamed:@"path" parentElement:update];
if (versionXML == nil) {
[Tool ToastNotification:@"获取版本信息错误" andView:self.view andLoading:NO andIsBottom:NO];
return;
}
versionPath = [TBXML textForElement:pathXML];
NSString *version = [TBXML textForElement:versionXML];
if ([MenuViewController getVersionNumber:version]>[MenuViewController getVersionNumber:AppVersion]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"天翼视讯iPhone推流客户端有新版了\n您需要下载吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
[alert show];
}
else
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您当前已经是最新版本" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
[alert show];
}
这里有pch文件中定义
#define AppVersion @"1.0.0"
这个是当前版本,后面有新版本程序的时候,修改summary的版本时不要忘记修改这里,不然就要一直提示有更新了当版本号大于当前版本,就提示更新,用户点击确认后,跳转
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
//下载
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:versionPath]];
}
}
2. 现在,开发阶段,应用程序没有放在appstore,想安装新的app
我们需要将工程生成ipa文件和关于ipa文件信息的plist文件,然后程序里访问plist文件。
同样,使用xml文件保存版本信息
比如文件updateInfo_ios.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<updateInfo>
<version>1.0.1</version>
<description>软件升级!!!</description>
<path>http://192.168.21.96/AVPlayerDemo3.plist</path>
</updateInfo>
这里path是你的plist文件的路径。
下面来生成ipa和plist
先在summary里写好版本号,与xml文件的版本一致
选择product-》archive
选择最新的那个,然后选择distribute
这里最后主义要勾上“save for Enterprise Distribute”
然后下面Application URL:写上你的ipa要存放的路径,这个路径别人要访问的到。我就放在192.168.21.96服务器下的这个路径了
title我就随便写了
点击保存,我在桌面上生成了AVPlayerDemo3.ipa 和 AVPlayerDemo3.plist
将这两个文件放在服务器下,保证访问路径是path的路径
然后就ok了,访问的改一下
#pragma mark - alert view delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//确认下载更新包
if (buttonIndex == 1) {
//下载
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-services://?action=download-manifest&url=%@",versionPath]]];
}
}
就可以更新了