Cocoapod软件包在我的应用程序中不可用
问题描述:
我正在使用一些资源文件创建我自己的软件包。它基本上是这样定义的:Cocoapod软件包在我的应用程序中不可用
Pod::Spec.new do |s|
s.name = 'MyName'
s.version = '0.0.1'
s.license = { :type => 'MIT' }
s.homepage = 'not important'
s.authors = {
# authors
}
s.summary = '…'
# Source Info
s.source = {
# .. my sources
}
s.source_files = ['Sources/*.swift']
s.resource_bundle = {'MyNameBundle' => ['*.{storyboard,xib,png,jsbundle,meta}']}
s.ios.deployment_target = '9.0'
s.requires_arc = true
末
该吊舱安装了pod install
,我可以看到,资源文件都在MyName/Resources/
可用。到现在为止还挺好。
我甚至可以在我的Pods.pbxcodeproj
中看到有两个新目标:MyName
和MyNameBundle-Bundle
。
但事实是,当我尝试列出所有可用的软件包:
NSBundle.allBundles().forEach {
print("bundle identifier: \($0.bundleIdentifier) - path \($0.bundlePath)")
}
然后,它不会显示出来。
我错过了什么?
答
嗯,这是一个答案,但我不能真正解释它是如何工作的。如果有人有任何想法,请告诉我。
这个帖子在我的波德帮了我很多https://*.com/a/35903720/1427775
所以,我不得不添加一个空迅速类,以便它可以用来加载正确的NSBundle
let refreshBundle = NSBundle(forClass: MyEmptyClass.self)
let bundleURL = newBundle.resourceURL?.URLByAppendingPathComponent("MyBundle.bundle")
let bundle = NSBundle(URL: bundleURL!)!
好像不是所有NSBundle
都在启动时加载,此代码触发加载所需的包。