我试图将 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/