我有以下代码:
NSURL* saveToURL = [[NSURL alloc] initWithString:[self.recording filePath]];
NSLog([saveToURL absoluteString]);
NSLog(@"?");
NSLog([self.recording filePath]);,它输出以下内容
2013-08-07 15:51:32.182 SpyApp[49799:c07] ?
2013-08-07 15:51:32.183 SpyApp[49799:c07] /Users/Mike/Library/Application Support/iPhone Simulator/6.1/Applications/C9EDE058-5C8B-4B75-8638-D5A4265B348F/Documents/Recordings/ujaxvehvjlgwfuw在调试器中,我还可以看到saveToURL是nil,尽管[self.recording filePath]返回/Users/Mike/Library/Application Support/iPhone Simulator/6.1/Applications/C9EDE058-5C8B-4B75-8638-D5A4265B348F/Documents/Recordings/ujaxvehvjlgwfuw
为什么会这样呢?我该怎么解决呢?
发布于 2013-08-07 19:57:19
因为filePath是路径,而不是URL。若要创建文件URL,请使用不同的方法:
NSURL* saveToURL = [[NSURL alloc] initFileURLWithPath:[self.recording filePath]];另外,NSLog的第一个参数应该始终是一个常量字符串,您永远不知道filePath何时可以在其中包含一个%。
NSLog(@"%@", [saveToURL absoluteString]);
NSLog(@"?");
NSLog(@"%@", [self.recording filePath]);https://stackoverflow.com/questions/18112623
复制相似问题