ios - NSBundle 路径中的 NSURL 返回 nil

标签 ios nsurl nsbundle

所以我尝试使用视频作为背景,并且我的应用程序中有一个 .mov 文件,当我运行此代码时:

NSBundle * bundle = [NSBundle mainBundle];

NSString * urlString = [bundle pathForResource:@"movie" ofType:@"mov"];
NSURL * movieURL = [NSURL URLWithString:urlString];

if (!movieURL) {

    NSLog(@"Not valid");

}

我在控制台中收到无效。我检查了 urlString,它给了我一个 url,我确信该文件命名正确并且不在目录中。

So its here...

所以文件就在那里并被复制到源中。不知道为什么要这样做。

最佳答案

您想使用:

NSURL *moveiURL = [NSURL fileURLWithPath:urlString];

更好的是,使用:

NSURL *moveURL = [bundle URLForResource:@"movie" withExtension:@"mov"];

关于ios - NSBundle 路径中的 NSURL 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25633573/

相关文章:

ios - 将 UIImage 传递给 MKPinAnnotationView 时遇到问题

c++ - 将数据从 .cpp 文件传递​​到 Objective c ViewController

ios - NSURL 需要很长时间才能返回 URL 的内容。有没有办法加快速度?

objective-c - NSFileManager应用程序文件夹-iOS

cocoapods - Cocoapod bundle 在我的应用程序中不可用

ios - 是否可以修改 iOS 应用程序的主包?

ios - 查看 UICollectionViewCell 的调试?

ios - 是否可以使用 SKScene 数组实现 iCarousel?

iphone - iOS - 为什么我的 NSURL 没有保留在 init 方法中?

iphone - coredata问题nsurl可能无法响应stringByAppendingPathComponent