gpt4 book ai didi

ios - NSMainbundle 到 NSDocumentsDirectory - 复制 PDF

转载 作者:行者123 更新时间:2023-11-28 20:30:02 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com