Objective c initWithContentsOfURL的编码是什么?

Objective c initWithContentsOfURL的编码是什么?,objective-c,xcode,nsurl,nsfilemanager,initwithcontentsofurl,Objective C,Xcode,Nsurl,Nsfilemanager,Initwithcontentsofurl,嗨,我保存了一个URL,它有一个指向我将要存储信息的目录的路径,现在我想检索信息,但我不知道如何接收项目,我正在尝试使用initWithContentsOfURL,但我不知道编码是什么 这就是我保存URL的方式 //DirectoryPaths has the NSCAcheDirectory dirPath = [[directoryPaths objectAtIndex:0] URLByAppendingPathComponent:[NSString stringWithFormat:@"

嗨,我保存了一个URL,它有一个指向我将要存储信息的目录的路径,现在我想检索信息,但我不知道如何接收项目,我正在尝试使用initWithContentsOfURL,但我不知道编码是什么

这就是我保存URL的方式

//DirectoryPaths has the NSCAcheDirectory
 dirPath = [[directoryPaths objectAtIndex:0] URLByAppendingPathComponent:[NSString stringWithFormat:@"photos.jpg"]];
现在如何获取URL的路径?我试过了

  NSString *pathToFile = [[NSString alloc] initWithContentsOfURL:dirPath
                                                 usedEncoding:nil
                                                        error:&error];

我不知道编码是什么,因为我没有使用编码来存储文件。

我想你误解了
initWithContentsOfURL:usedEncoding:error:
从URL加载字符串。因此,您需要指定用于字符串的编码-UTF-8、ASCII或类似的东西


要从URL获取磁盘路径,您可能需要
[dirPath path]
。实际上,您可能只是从URL加载,而不是硬编码本地磁盘行为。

使用NSUTF8StringEncoding或ASCII。它对我有用。:)