NSURL isFileURL总是返回NO [英] NSURL isFileURL always returns NO
问题描述
NSString * filePathString = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)[/ b]可以有人向我解释为什么下面的代码: 0];
NSLog(@%i,[[NSURL URLWithString:filePathString] isFileURL]);
NSLog(@%@,filePathString);
输出:
0
/ var / mobile / Applications / 28ADFC19-874C-4304-94B5-F6441CAE9FAD / Documents
这意味着这个URL不是一个文件的URL。显然是这样。
背景: 我尝试使用AVCaptureMovieFileOutput将影片录制到文件中,但是我证明的文件url提供了错误: *终止应用程序由于未捕获异常'NSInvalidArgumentException',原因:'* - [AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - 无法记录到URL / var / mobile / Applications / 28ADFC19-874C-4304-94B5-F6441CAE9FAD / Documents / media / CrKNjNhe9so2LRnD9iHK.mov,因为它不是一个文件的URL。 这就像是一个文件的URL给我,就像原来的例子。如果你想创建一个 一个 Can someone explain to me why the following code: outputs: 0 "/var/mobile/Applications/28ADFC19-874C-4304-94B5-F6441CAE9FAD/Documents" This means that this url isn't a file URL. Obviously, it is. Background: I'm trying to use an AVCaptureMovieFileOutput to write a movie recording to a file, but the file url I'm proving gives the error: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - Cannot record to URL /var/mobile/Applications/28ADFC19-874C-4304-94B5-F6441CAE9FAD/Documents/media/CrKNjNhe9so2LRnD9iHK.mov because it is not a file URL.' That looks like a file URL to me, just like the original example. What gives? If you want to create an An 这篇关于NSURL isFileURL总是返回NO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
NSURL
,那么你可以创建一个名为的
NSURL fileURLWithPath:
。 URLWithString
的使用假定该字符串是一个非文件URL。
NSURL
只有以 file://
开头的文件URL。NSString* filePathString = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSLog(@"%i", [[NSURL URLWithString:filePathString] isFileURL]);
NSLog(@"%@", filePathString);
NSURL
from a file path, you must use NSURL fileURLWithPath:
. The use of URLWithString
assumes the string is a non-file URL.NSURL
is a file URL only if it begins with file://
.