AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];

//下载地址

NSURL*mgrurl = [NSURLURLWithString:self.updateUrl];

NSURLRequest*request = [NSURLRequestrequestWithURL:mgrurl];

NSURLSessionDownloadTask*download = [mgrdownloadTaskWithRequest:requestprogress:^(NSProgress*_NonnulldownloadProgress) {

//在主线程中调用

[[NSOperationQueue mainQueue]addOperationWithBlock:^{

NSLog(@"进度%f",1.0*downloadProgress.completedUnitCount/ downloadProgress.totalUnitCount);

CGFloatjsw =1.0* downloadProgress.completedUnitCount/ downloadProgress.totalUnitCount* (PW-40);

self.jdView.frame=CGRectMake(0,0, jsw,5);

self.jdText.text= [NSStringstringWithFormat:@"更新进度(%.0f/100)",100.0*downloadProgress.completedUnitCount/ downloadProgress.totalUnitCount];

self.suduText.text= [NSStringstringWithFormat:@"%lldkb/s",[MLRNSingtongetInterfaceBytes]/1024/1024];

}];

}destination:^NSURL*_Nonnull(NSURL*_NonnulltargetPath,NSURLResponse*_Nonnullresponse) {

NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:response.suggestedFilename];

NSLog(@"targetPath:%@",targetPath);

NSLog(@"fullPath:%@",fullPath);

return[NSURLfileURLWithPath:fullPath];

}completionHandler:^(NSURLResponse*_Nonnullresponse,NSURL*_NullablefilePath,NSError*_Nullableerror) {

//下载完成,解压

//Caches路径

NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];

NSString *xxxx = [[filePath absoluteString] substringFromIndex:7];

[SSZipArchive unzipFileAtPath: xxxx toDestination:cachesPath];

[[NSOperationQueue mainQueue]addOperationWithBlock:^{

[MBProgressHUD hideHUD];

UIStoryboard*storayobard = [UIStoryboardstoryboardWithName:@"main"bundle:nil];

self.view.window.rootViewController = storayobard.instantiateInitialViewController;

}];

}];

[downloadresume];

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐