ios自动更新(一)
来源:互联网 发布:convertfrom json 编辑:程序博客网 时间:2024/06/01 09:01
apple 现在虽然不然热更新了,但是好多时候,我们会发现为了解决一点小问题就需要重新上线的尴尬,为了解决这个问题,分享服务器更新的思路,希望对大家有所帮助
首先我们应该创建版本更新管理类,主要的方法如下所示
1. 判断是否是第一次启动app,如果是第一次启动,将资源文件copy到沙盒
// 如果沙箱指定目录已存在,先删除他
if([fileManagerfileExistsAtPath:[[selfclass]resourceRootPath]]) {
if(![fileManagerremoveItemAtPath:[[selfclass]resourceRootPath]error:&error]) {
DLog(@"remove resourceFolder error: %@", error.localizedDescription);
returnNO;
}
}
// 拷贝资源文件到沙箱指定目录
NSString *bundlePath = [[NSBundlemainBundle]pathForResource:bundleNameofType:nil];
if(![fileManagercopyItemAtPath:bundlePathtoPath:[[selfclass]resourceRootPath]error:&error]) {
DLog(@"copy resource files error: %@", error.localizedDescription);
returnNO;
if([fileManagerfileExistsAtPath:[[selfclass]resourceRootPath]]) {
if(![fileManagerremoveItemAtPath:[[selfclass]resourceRootPath]error:&error]) {
DLog(@"remove resourceFolder error: %@", error.localizedDescription);
returnNO;
}
}
// 拷贝资源文件到沙箱指定目录
NSString *bundlePath = [[NSBundlemainBundle]pathForResource:bundleNameofType:nil];
if(![fileManagercopyItemAtPath:bundlePathtoPath:[[selfclass]resourceRootPath]error:&error]) {
DLog(@"copy resource files error: %@", error.localizedDescription);
returnNO;
}
2. 初始化文件索引,将沙盒中的资源文件的索引添加到sqlite 数据库
3. 检查更新,将数据库中的版本号和服务器上的版本号进行对比,如果服务器上的版本号大,在沙盒中创建新版本的资源目录,并且开始下载服务器文件,更新数据库
// 开始下载,文件名会自动去取url的文件名
NSURLRequest *request = [NSURLRequestrequestWithURL:[NSURLURLWithString:versionRecord.downurl]cachePolicy:NSURLRequestReloadIgnoringCacheDatatimeoutInterval:60];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperationalloc]initWithRequest:requesttargetPath:targetFullPathshouldResume:YES];
operation.shouldOverwrite = YES;
[operationsetCompletionBlockWithSuccess:^(AFHTTPRequestOperation * _Nonnull operation,id _Nonnull responseObject) {
// 下载成功才更新索引数据库
[[selfclass]updateIndexDB:versionRecord];
DLog(@"update file \"%@/%@\" from version %ld to version %ld",versionRecord.filepath, versionRecord.filename, version, versionRecord.versionno);
}failure:^(AFHTTPRequestOperation * _Nonnull operation,NSError *_Nonnull error) {
DLog(@"download resource(%@) error: %@", operation.request.URL.absoluteString, error.localizedDescription);
}];
NSURLRequest *request = [NSURLRequestrequestWithURL:[NSURLURLWithString:versionRecord.downurl]cachePolicy:NSURLRequestReloadIgnoringCacheDatatimeoutInterval:60];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperationalloc]initWithRequest:requesttargetPath:targetFullPathshouldResume:YES];
operation.shouldOverwrite = YES;
[operationsetCompletionBlockWithSuccess:^(AFHTTPRequestOperation * _Nonnull operation,id _Nonnull responseObject) {
// 下载成功才更新索引数据库
[[selfclass]updateIndexDB:versionRecord];
DLog(@"update file \"%@/%@\" from version %ld to version %ld",versionRecord.filepath, versionRecord.filename, version, versionRecord.versionno);
}failure:^(AFHTTPRequestOperation * _Nonnull operation,NSError *_Nonnull error) {
DLog(@"download resource(%@) error: %@", operation.request.URL.absoluteString, error.localizedDescription);
}];
[[NSOperationQueuemainQueue]addOperation:operation];
阅读全文
0 0
- ios自动更新(一)
- iOS自动更新
- BareBox 移植及系统自动更新(一)
- iOS app自动更新
- iOS自动更新版本号脚本
- 第三天 iOS自动更新
- iOS自动更新如何实现
- Windows自动更新API (一)
- iOS-自动更新订阅IAP浅谈(设置和测试)
- 移动应用(Android,IOS)自动更新替换方案
- 基于C/S自动更新系统设计(一)
- 「Maven Tips」(一)自动更新jar包
- VS 程序自动更新——(方案一)
- IOS开发-设置APP自动更新
- iOS自动更新提醒第三方类库
- 页面自动更新(javascript)
- 自动更新系统(二)
- 自动更新系统(三)
- BZOJ3165: [Heoi2013]Segment(线段树)
- spring boot 404不匹配路径问题
- Java面试题大汇总
- 最小生成树Prim算法朴素版 C语言实现
- Java 基础总结
- ios自动更新(一)
- 给定Json数据格式,提取相关数据
- Unity3d 判断手势触摸的类型 ,判断手势的滑动方向,并获取刚触摸以及触摸结束事的坐标
- java面经----大公司必问
- ELF头解析
- 大数据的一些相关知识介绍
- PAT
- 最近工作总结
- git常用命令总结(一)