我是iphone开发新手。我正在开发iPhone应用程序在我使用的Web服务,下面的代码下载文件:在iphone中打开下载的文件在webview中
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = [paths objectAtIndex:0];
NSString *fileLoc = [basePath stringByAppendingString:@"/filename.pdf"];
NSData *fileData = [self decodeBase64WithString:soapResults];
[fileData writeToFile:fileLoc atomically:YES];
我的文件路径:/用户/名为myUsername /库/应用程序支持/ iPhone模拟器/ 4.0 /应用/ 7A627E64-DEAB-40FA-BE04-35ED50580B65/filename.pdf
如何使用uiwebview打开此文件?我尝试这样做:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = [paths objectAtIndex:0];
NSString *fileLoc = [basePath stringByAppendingString:@"/filename"];
[self loadDocument:fileLoc inView:mywebview];
我loadDocument方法是:
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
但它显示的错误......我觉得位置是问题..我怎样才能找到模拟器的路径,以及在信号设备?
请帮助我...
非常感谢...它的工作... – itdeeps
这个相同的文件位置是否适用于原始设备? – itdeeps
是的。 'NSSearchPathForDirectoriesInDomains'为设备和模拟器返回适当的路径。 – cduhn