300分求问大神

哎,真难 2015-07-20 10:15:20
需求是这样的,我写了一个webview,用html5写的,html5里面有一个连接,判断该链接是否为下载链接,下载链接就让它下载,
那么问题来了,我现在已经判断出下载链接了,这是别人分别写的两个下载类
第一个别人写的下载方法
- (void) downloadFileWithUrl: (NSString*)fileUrl {
NSString *filePath = fileUrl;
NSString *fileHost ;
fileHost = HOST_ADDRESS;
NSString *tempPath = NSTemporaryDirectory();
localFilePath = [NSString stringWithFormat:@"%@%@.pdf",tempPath,filePath];
[self clearParameter];
[self setDownLoadUrl:filePath];
[self downloadToFile:localFilePath];//设置存放路径的地址
[self setShowWaiting:YES];
}

我是这样调用的
FileDownloadNetworkAction *fileDownLoad = [FileDownloadNetworkAction new];
[fileDownLoad downloadFileWithUrl:filePath];

debug的时候可以进去,但是下载了,然后了?没反应,我也不知道是否下载好了,求问这个地方如果要加提示,下载完成请用什么打开该如何去做?

第二个别人写的方法,是直接一个view,下载好了,就打开显示在这个view里面,view的名字叫FileViewController,里面有个方法就是用于显示的
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSDictionary *cellFileData = [[[[fileFormData getFileFormGroupArray] objectAtIndex:indexPath.section] valueForKey:@"groupData"] objectAtIndex:indexPath.row];
NSString *url = [cellFileData valueForKey:@"pdfUrl"];
pdfUrl = url;

if ([[cellFileData valueForKey:@"prefix"] isEqualToString:@"正文"] || [[cellFileData valueForKey:@"prefix"] isEqualToString:@"处理单"] || [[cellFileData valueForKey:@"prefix"] isEqualToString:@"稿纸"]) {
fileTitle = [self.fileData valueForKey:@"title"];
if (!fileTitle) {
fileTitle = [self.fileData valueForKey:@"name"];
}
}else{
fileTitle = [NSString stringWithFormat:@"%@",[cellFileData valueForKey:@"title"]];
}

if ([[pdfUrl lastPathComponent] isEqualToString:@"null"]){
[self.rootVC showHudText:@"文件打开失败"];
return;
}
if (isIntegrated){
pdfUrl = [YXFramework chanegPath:pdfUrl newIp:[[NSUserDefaults standardUserDefaults] valueForKey:@"Server_IP"]];
}
[self downloadFileURL:pdfUrl savePath:NSTemporaryDirectory() fileName:[NSString stringWithFormat:@"%@%@",[cellFileData valueForKey:@"title"],@".pdf"] withTitle:fileTitle];
//
}

- (void)downloadFileURL:(NSString *)aUrl savePath:(NSString *)aSavePath fileName:(NSString *)aFileName withTitle:(NSString*)title
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fileName = [NSString stringWithFormat:@"%@%@", aSavePath, [aUrl lastPathComponent]];

if ([fileManager fileExistsAtPath:fileName]) {
[self.rootVC showFile:fileName title:title];
}else{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"下载中";
if (![fileManager fileExistsAtPath:aSavePath]) {
[fileManager createDirectoryAtPath:aSavePath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSURL *url = [[NSURL alloc] initWithString:aUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.inputStream = [NSInputStream inputStreamWithURL:url];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:fileName append:NO];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {

NSLog(@"is download:%f", (float)totalBytesRead/totalBytesExpectedToRead);
hud.progress = (float)totalBytesRead/totalBytesExpectedToRead;
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
DLog(@"下载成功");
[hud hide:YES];
NSString *filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), [aUrl lastPathComponent]];
//[self performSelector:@selector(showFile:) withObject:[NSArray arrayWithObjects:filePath,title, nil] afterDelay:0.5];
[self.rootVC showFile:filePath title:title];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
DLog(@"下载失败");
[self showHudText:@"下载失败"];
[hud hide:YES];
}];

[operation start];
}
}



这个方法下载好,就会直接打开文件,我很想调用这个view,在我的webview里面,如果下载好了,就调用这个view去显示出来,但是不会,求问大神支招????
...全文
108 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
哎,真难 2015-07-22
  • 打赏
  • 举报
回复
引用 2 楼 rui888 的回复:
第一个 加个进度条呢
算了,改变需求了。。。
tony4geek 2015-07-22
  • 打赏
  • 举报
回复
tony4geek 2015-07-22
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
既然需求变了 不介意来蹭个分吧

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧