-1

以下是我所拥有的

NSString *foofile = @"/Users/alkandari/Library/Application Support/iPhone Simulator/6.1/Applications/8C445026-6387-4E40-B5A3-D1A1680666D6/Documents/ProjacsBODFiles/file_5_21.pdf"
NSURL *url;
if (fileExists) {
    url = [NSURL URLWithString:foofile];
    NSLog(@"taking local file 1 ... %@==%@", url, foofile);
} else {

    url=[NSURL URLWithString:address];
    NSLog(@"taking internet file 1... %@", url);
}

当我执行时,我得到如下日志

taking local file 1 ... (null)==/Users/alkandari/Library/Application Support/iPhone Simulator/6.1/Applications/8C445026-6387-4E40-B5A3-D1A1680666D6/Documents/ProjacsBODFiles/file_5_21.pdf

我不明白为什么我将 URL 设为空。因此,我无法打开文件。

知道为什么我在上面将 URL 设为 null 吗?

4

2 回答 2

1

您将需要使用fileURLWithPath本地文件系统的路径:

NSString *foofile = @"/Users/alkandari/Library/Application Support/iPhone Simulator/6.1/Applications/8C445026-6387-4E40-B5A3-D1A1680666D6/Documents/ProjacsBODFiles/file_5_21.pdf"
NSURL *url;
if (fileExists) {
    url = [NSURL fileURLWithPath:foofile];
    NSLog(@"taking local file 1 ... %@==%@", url, foofile);
} else {
...
}
于 2013-05-21T10:20:44.850 回答
1

您还可以使用以下代码访问模拟器文件夹中的文件;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *libraryBaseDirectory = [paths objectAtIndex:0];

NSString *privateDocumentsDirectory = [libraryBaseDirectory stringByAppendingPathComponent:@"ProjacsBODFiles"];
于 2013-05-21T12:55:43.250 回答