[英]Check if Documents Directory Url empty
在下面的代码中,我试图检查我的Documents Directory Url是否为空,因此,如果它为空,它将立即显示或继续执行我所需的一切。
这是我的代码:
- (IBAction)saveVideo:(id)sender {
NSURL *vedioURL;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"files array %@", filePathsArray);
NSString *fullpath;
for ( NSString *apath in filePathsArray )
{
fullpath = [documentsDirectory stringByAppendingPathComponent:apath];
vedioURL =[NSURL fileURLWithPath:fullpath];
}
NSLog(@"vurl %@",vedioURL);
NSURL *movieUrl = [NSURL fileURLWithPath:fullpath];
NSString *moviePath = [movieUrl path];
if (videoUrl.absoluteString.length == 0) {
NSLog(@"No way");
} else {
self.imageViewPost.image = [self generateThumbImage:moviePath];
AVPlayerItem * playeritem = [AVPlayerItem playerItemWithURL:vedioURL];
[_player replaceCurrentItemWithPlayerItem:playeritem];
[_player play];
[self clearTmpDirectory];
}
}
应用程序崩溃了,它向我的网址显示了Null值:
vurl (null)
2017-11-29 20:54:24.288473+0400 EasyVideo[43587:2429960] ***
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
我希望解决这个问题。 谢谢
您可以先从URL获取数据,然后检查数据是否为空。
NSData *data = [NSData dataWithContentsOfURL:videoURL];
在这里,如果数据不为空,您将相应地执行任务:
if (data == nil)
{
//Do not perform the task.
}
else
{
//perform the task
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.