我正在尝试将下载的文件复制到应用程序文档目录中的特定文件夹,但似乎无法正常工作。我正在使用的代码是:
NSString *itemPathString = @"http://pathToFolder/folder/myFile.doc";
NSURL *myUrl = [NSURL URLWithString:itemPathString];
NSArray *paths = [fm URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
NSURL *folderPath = [[paths objectAtIndex:0] URLByAppendingPathComponent:@"folder"];
NSURL *itemURL = [documentsPath URLByAppendingPathComponent:@"myFile.doc"];
// copy to documents directory asynchronously
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSFileManager *theFM = [[NSFileManager alloc] init];
NSError *error;
[theFM copyItemAtURL:myUrl toURL:itemURL error:&error];
}
});
我可以正常检索文件,但无法复制它。谁能告诉我上面的代码有什么问题吗?