服务器更新是热部署项目,React-Native做本地服务器热更新/热部署(IOS)
AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];//下载地址NSURL*mgrurl = [NSURLURLWithString:self.updateUrl];NSURLRequest*request = [NSURLRequestrequestWithURL:mgrurl];NSURLSessionDownloadTask*
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];
更多推荐
所有评论(0)