是否有可能在我的应用程序中下载实现UI web iphone的文件?如果是的话,这些文件将被存储在哪里,我如何访问它?使用用户界面web视图下载文件
0
A
回答
1
你真的无法下载文件只需通过浏览到他们,但你可以做的是使用
- (BOOL)webView的:(UIWebView的*)webView的shouldStartLoadWithRequest:(*的NSURLRequest)请求navigationType:(UIWebViewNavigationType )navigationType
分析(链接为一个文件,说通过看最后一个部分的扩展名),如果你想这种文件被下载超过您可以用[NSURLConnection的connectionWithRequest:myURLRequest委托:自我]。及其所有关联的委托方法下载文件并将其存储在文档文件夹中。
0
如果你想显示一些已知的webview文件,它会自动显示你...但是如果页面回传一个未知的webview文件(这发生在我与Citrix ica文件)webview会给你一个错误。 ......要解决这个问题,我用这个代码(注意,在这里,我将允许只下载ICA文件,但你可以改变这种状况):
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
if([error code]!=102)
{ [self.lblError setText:[NSString stringWithFormat:@"%@",error]];
return;
}
NSDictionary *userInfo = [error userInfo];
NSString * url = [[NSString alloc] initWithFormat:@"%@",[userInfo objectForKey:@"NSErrorFailingURLKey"] ];
NSString *search = @"?";
NSRange result = [url rangeOfString:search];
NSInteger startingPosition;
NSString *fileName,*fileExtention,*fileLocation;
if (result.location != NSNotFound) {
startingPosition = result.location + result.length;
fileLocation = [url substringToIndex:result.location];
fileExtention=[fileLocation pathExtension];
}
else
{
fileLocation=url;
}
fileName = [fileLocation lastPathComponent];
fileExtention=[fileLocation pathExtension];
//check if file to download if ica file
if(![fileExtention isEqualToString:@"ica"])
return;
self.lblError.textColor=[UIColor blackColor];
self.lblError.text=[NSString stringWithFormat:@"downloading %@...",fileName];
NSURL * _url = [[NSURL alloc] initWithString:url];
// Get file online
NSData *fileOnline = [[NSData alloc] initWithContentsOfURL:_url];
// Write file to the Documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
// NSLog(@"Documents directory not found!");
return;
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
//NSLog(@"appFile path: %@",appFile);
[fileOnline writeToFile:appFile atomically:YES];
NSURL* aUrl = [NSURL fileURLWithPath:appFile];
self.interactionController = [UIDocumentInteractionController interactionControllerWithURL: aUrl];
self.interactionController.delegate = self;
self.lblError.text=[NSString stringWithFormat:@"%@ downloaded",fileName];
[self.interactionController presentOpenInMenuFromRect:self.lblError.frame inView:self.view animated:YES];
}
相关问题
- 1. 加载HTML页面到用户界面web视图iPhone SDK 4.0
- 2. 从luci网络用户界面下载文件(openWrt Luci)
- 3. 图形用户界面FileViewer程序文件加载问题
- 4. Android 3D用户界面视图
- 5. Android用户界面:大小2视图?
- 6. Android用户界面 - 视图滑块
- 7. 用户界面视图太大
- 8. 使用Web API调用下载文件
- 9. 试图使用谷歌地图的用户界面在Django上下载Lat/Lon
- 10. 用户界面图像视图使用滚动查看动画
- 11. 用户界面 - 下拉
- 12. AngularJS用户界面视图顶部不加载ngOptions
- 13. 阻止用户界面Interation虽然图像正在下载
- 14. 使用Hadoop的图形用户界面
- 15. 图形用户界面使用OpenCV
- 16. 创建通用用户界面文件
- 17. 使用WEB API模拟文件下载
- 18. 从Web C++下载文件(使用winsock?)
- 19. 使用Dropbox的Web界面来删除文件夹30,000文件
- 20. 使用Web界面的SSIS
- 21. 图形用户界面不文本
- 22. UI路由器的用户界面视图基于主视图
- 23. Java图形用户界面
- 24. 图形用户界面
- 25. 图形用户界面
- 26. 图形用户界面 - Tkinter
- 27. 我无法让用户界面文本视图键盘消失
- 28. 使用Netbeans来设计图形用户界面并能够使用Web Start
- 29. 使用webview下载视频文件
- 30. Eclipse Kura WEB用户界面未显示