Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURL isFileURL always returns NO

Can someone explain to me why the following code:

NSString* filePathString = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

NSLog(@"%i", [[NSURL URLWithString:filePathString] isFileURL]);
NSLog(@"%@", filePathString);

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?

like image 335
eric.mitchell Avatar asked Nov 26 '12 00:11

eric.mitchell


1 Answers

If you want to create an NSURL from a file path, you must use NSURL fileURLWithPath:. The use of URLWithString assumes the string is a non-file URL.

An NSURL is a file URL only if it begins with file://.

like image 156
rmaddy Avatar answered Sep 22 '22 20:09

rmaddy