Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在本地存储pdf在iphone中不起作用_Iphone_Objective C_Ios - Fatal编程技术网

在本地存储pdf在iphone中不起作用

在本地存储pdf在iphone中不起作用,iphone,objective-c,ios,Iphone,Objective C,Ios,我是iPhone开发新手。我想使用url下载pdf并将其存储在本地文件夹中 这是我的密码: NSData *d = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://demo.com/ebookapplication/book_pdf/20111108094614hii.pdf"]]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocument

我是iPhone开发新手。我想使用url下载pdf并将其存储在本地文件夹中

这是我的密码:

NSData *d = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://demo.com/ebookapplication/book_pdf/20111108094614hii.pdf"]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myfile.pdf"]; 
[d writeToFile:path atomically:YES];
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSString *myPathInfo = [[NSBundle mainBundle] pathForResource:@"myfile" ofType:@"pdf"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager copyItemAtPath:myPathInfo toPath:path error:NULL];
}
 NSURL *pdfurl = [NSURL fileURLWithPath:path];
 NSURLRequest *requestObj = [NSURLRequest requestWithURL:pdfurl];
[detail.bookweb loadRequest:requestObj];//to display data in web view

这段代码用于使用url在web视图中显示pdf,但不用于在本地系统中存储pdf。实际上,我想把这些下载的pdf存储在一个文件夹中,并以库格式显示。请提供帮助。

-writeToFile:atomicaly已将您的文件放置在您在-copyItemAtPath:toPath:method中指定的文件夹中,因此是多余的。文档已经在文档目录文件夹中,然后您将其复制到同一目录!我想这是你的问题

编辑:

这一行在这里:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myfile.pdf"]; 
指定您的路径

您可以使用以下行
NSLog
it:
NSLog(@“documentpath=%@”,Path)

至于你的图书馆评论,应该没那么难。我的应用程序基本上已经做到了这一点 AQGridView:

以及来自DITableView的Apple Docwatcher类:


一起创建一个应用程序,该应用程序可以控制文档目录,并将文件添加到NSArray,然后由网格显示。一个更简单的方法是使用DITableViewController,不过考虑到它可以解决您的问题,网格只是为了多一点比萨饼。

您所说的
存储在本地系统中的意思是什么?您已经在本地将该文件存储到文档文件夹中。在本地系统中存储意味着我希望将该文件存储在我的项目文件夹中的某个其他位置,从该位置我可以读取该文件。我已在文档文件夹中搜索了该文件,但未获得该文件。我使用的是xcode 4.2tanks CodaFi,我可以使用Docwatcher来实现库。但您能告诉我如何解决文件复制问题吗?我想将所有pdf文件存储在一个文件夹中。如何设置该文件夹的路径?但在哪里设置此路径?我是说文件夹名?若它是文档文件夹,我已经搜索了文档文件夹中的文件,但文件不存在。plz帮助