ios - BundlePath 为零,但 NSLog 打印正确的路径

标签 ios objective-c

我尝试从框架内的包中获取资源。如您所见,bundlePath 为零。但 NSLog 打印正确的路径。并且捆绑为零。为什么?

enter image description here

最佳答案

不确定为什么会发生这种情况,但代码效率低下,因为您获得了一个 bundle 以分配一个新的 bundle 。这显然是不必要的:

NSBundle *bundle = [NSBundle mainBundle];
NSURL *modelURL = [bundle URLForResource:... ];

<罢工>

我在回答这个问题时漏掉了框架元素。当您从框架代码中调用此代码时,我假设 [NSBundle mainBundle]正在返回框架的 bundle 而不是应用程序。

答案在于应用程序通过某种方法将框架代码与应用程序的 bundle 一起提供。然后,框架代码应该能够访问应用程序包中的文件。

关于ios - BundlePath 为零,但 NSLog 打印正确的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24634820/

相关文章:

iphone - 应用商店 : blocking the game for 3G- devices

ios - 状态栏和 UI 方向不匹配

ios - UILocalNotification 从应用文档播放声音

ios - 如何在 iOS 上重现带有 Spark 的 watchOS 关闭事件环动画?

ios - 使 UICollectionView 看起来像 iOS 日历应用程序的最佳方法

objective-c - 将值添加到顶点数组

ios - ReactiveCocoa 将单个信号转换为值

iOS 性能调优 : fastest way to get pixel color for large images

ios - 如何覆盖我的应用程序委托(delegate)的方法?

ios - CMTimeMake(持续时间,fps)。这是什么意思?