NSURL isFileURL总是返回NO [英] NSURL isFileURL always returns NO

查看:592
本文介绍了NSURL isFileURL总是返回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给我,就像原来的例子。如果你想创建一个 NSURL ,那么你可以创建一个名为

解决方案文件路径,您必须使用 NSURL fileURLWithPath: URLWithString 的使用假定该字符串是一个非文件URL。

一个 NSURL 只有以 file:// 开头的文件URL。


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?

解决方案

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://.

这篇关于NSURL isFileURL总是返回NO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆