无法从pod库访问捆绑包

时间:2017-04-28 13:10:51

标签: ios swift xcode cocoapods bundle

我尝试在我的项目中使用PEPhotoCropLibrary。我使用cocoapods安装程序添加它。但是当我尝试在我的代码中使用它时,我收到错误:

  

由于未捕获的异常而终止应用   ' NSInvalidArgumentException',原因:' - [NSBundle initWithURL:]:无   网址参数'

这发生在这里:

NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"PEPhotoCropEditor" withExtension:@"bundle"];

然后我尝试在我的代码中访问PEPhotoCropEditor.bundle

let url = Bundle.main.url(forResource: "PEPhotoCropEditor", withExtension: "bundle")

并获得nil作为结果。项目结构如下: enter image description here

这里有什么问题,为什么我无法访问库捆绑包?

1 个答案:

答案 0 :(得分:1)

请更改:

NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"PEPhotoCropEditor" withExtension:@"bundle"];

为:

NSURL *bundleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"PEPhotoCropEditor" withExtension:@"bundle"];