項(xiàng)目中一些代碼是一framework或.a等SDK形式集成進(jìn)來的策菜,而SDK中使用到了資源文件,這時候需要把這些資源文件包括圖片酒贬、xib又憨、storyboard等打包到一個bundle中。
踩坑過程不細(xì)說了同衣,bundle本身是一個文件夾竟块,直接拖入到Xcode項(xiàng)目中,是不會自動編譯里面的資源文件的耐齐。需要新建一個bundle target浪秘,同時要正確配置bundle的引入,否則bundle編譯時可能不會被復(fù)制到app這個包中埠况,導(dǎo)致項(xiàng)目中的代碼獲取不到耸携。
新建一個 macOS 的 bundle target,將
Base SDK
由last macOS
改為last iOS
將需要用到的資源文件包括png辕翰、xib夺衍、storyboard等復(fù)制到這個target文件夾下,并確認(rèn)
build phases
下的compy bundle resource
有正確引入這些文件-
在 bundle target 中
Build Phases
下的COMBINE_HIDPI_IMAGES
設(shè)置為NO防止png格式被編譯為tiff
在 app target 中的
embedded binaries
中引入新建的bundele喜命,在build phases
選項(xiàng)卡的copy Files
將Destination改為Resource沟沙。
// 獲取圖片
[UIImage imageNamed:[NSString stringWithFormat:@"Resources.bundle/%@",imageName]];
// 獲取 storyboard
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *bundlePath = [bundle pathForResource:@"Resources" ofType:@"bundle"];
if (bundlePath) {
bundle = [NSBundle bundleWithPath:bundlePath];
}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"HLImagePicker" bundle:bundle];