ios - NSMainbundle 到 NSDocumentsDirectory - 复制 PDF

标签 ios xcode uiwebview nsdocumentdirectory

我试图将 NSMainBundle 中的现有 pdf 文件复制到 NSDocumentsDirectory 中。该文件稍后加载到 uiwebview 中。我似乎不明白为什么它不复制文件。有什么帮助吗?

 NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *resourceDBFolderPath = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"];


[fileManager copyItemAtPath:resourceDBFolderPath toPath:documentsDirectory error:&error];



NSArray *path1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath =  [path1 objectAtIndex:0];
NSString *fileLoc = [basePath stringByAppendingString:@"document.pdf"];
NSURL *url = [NSURL fileURLWithPath:fileLoc];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];

最佳答案

您的目标路径必须包含文件名。

来自文档:

dstPath

The path at which to place the copy of srcPath. This path must include the name of the file or directory in its new location. This parameter must not be nil.

关于ios - NSMainbundle 到 NSDocumentsDirectory - 复制 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12554680/

相关文章:

ios - 为什么当我添加新语言时,我的主 Storyboard 没有用于本地化?

iphone - 我应该在所有 iOS 项目的其他链接器标志中包含 "-ObjC and -all_load"吗?

objective-c - 抛出异常的简单 CoreData 示例

xcode - 无法将 cv.h 添加到项目中

iphone - iOS 从另一个 View Controller 加载 UIWebView 中的网页

ios - 具有可编辑 UIWebView 的自定义键盘?

ios - UIWebView 内容如何调整大小/缩放呢?

ios - [UIView _forgetDependentConstraint :]: message sent to deallocated instance

ios - 导航栏的右侧按钮丢失

ios - 将 Google Analytics 添加到我的 podfile 会破坏构建(找不到库)