ios设备版本更新

来源:互联网 发布:温庭筠入骨相思知不知 编辑:程序博客网 时间:2024/05/22 09:51
 


1. 应用程序已经放在appstore时更新比较简单,就是比较版本号,当发现版本高于当前版本时,就访问appstore应用程序所在位置,让用户决定是否更新。

使用xml文件保存版本信息,updateInfo_ios.xml内容如下

[cpp] view plaincopyprint?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <updateInfo>  
  3.   
  4.     <version>1.0.1</version>  
  5.   
  6.     <description>软件升级!!!</description>  
  7.   
  8.     <path>itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=524298520</path>  
  9.   
  10. </updateInfo>  


其中,version是新的版本号,path是应用程序在appstore的地址

使用TBXML读取从服务端请求来的xml文件内容,这里请求回来的是string类型

[cpp] view plaincopyprint?
  1. TBXML *xml = [[TBXML alloc] initWithXMLString:jsonString error:nil];  
  2.        TBXMLElement *update = xml.rootXMLElement;  
  3.        if (update == nil) {  
  4.            [Tool ToastNotification:@"获取版本信息错误" andView:self.view andLoading:NO andIsBottom:NO];  
  5.            return;  
  6.        }  
  7.          
  8.        TBXMLElement *versionXML = [TBXML childElementNamed:@"version" parentElement:update];  
  9.        if (versionXML == nil) {  
  10.            [Tool ToastNotification:@"获取版本信息错误" andView:self.view andLoading:NO andIsBottom:NO];  
  11.            return;  
  12.        }  
  13.        TBXMLElement *pathXML = [TBXML childElementNamed:@"path" parentElement:update];  
  14.        if (versionXML == nil) {  
  15.            [Tool ToastNotification:@"获取版本信息错误" andView:self.view andLoading:NO andIsBottom:NO];  
  16.            return;  
  17.        }  
  18.        versionPath = [TBXML textForElement:pathXML];  
  19.          
  20.        NSString *version = [TBXML textForElement:versionXML];  
  21.        if ([MenuViewController getVersionNumber:version]>[MenuViewController getVersionNumber:AppVersion]) {  
  22.            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"天翼视讯iPhone推流客户端有新版了\n您需要下载吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];  
  23.            [alert show];  
  24.        }  
  25.        else  
  26.        {  
  27.            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您当前已经是最新版本" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];  
  28.            [alert show];  
  29.        }  
这里有pch文件中定义

#define AppVersion @"1.0.0"

这个是当前版本,后面有新版本程序的时候,修改summary的版本时不要忘记修改这里,不然就要一直提示有更新了

当版本号大于当前版本,就提示更新,用户点击确认后,跳转

[cpp] view plaincopyprint?
  1. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  2. {  
  3.     if (buttonIndex == 1) {  
  4.         //下载  
  5.         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:versionPath]];  
  6.     }  
  7. }  


2. 现在,开发阶段,应用程序没有放在appstore,想安装新的app

我们需要将工程生成ipa文件和关于ipa文件信息的plist文件,然后程序里访问plist文件。

同样,使用xml文件保存版本信息

比如文件updateInfo_ios.xml内容如下:

[cpp] view plaincopyprint?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <updateInfo>  
  3.   
  4.     <version>1.0.1</version>  
  5.   
  6.     <description>软件升级!!!</description>  
  7.   
  8.     <path>http://192.168.21.96/AVPlayerDemo3.plist</path>  
  9.   
  10. </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了,访问的改一下

[cpp] view plaincopyprint?
  1. #pragma mark - alert view delegate  
  2. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  3. {  
  4.     //确认下载更新包  
  5.     if (buttonIndex == 1) {  
  6.         //下载  
  7.         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-services://?action=download-manifest&url=%@",versionPath]]];  
  8.     }  
  9. }  
就可以更新了
0 0
原创粉丝点击