Mid*_* MP 8 resources bundle static-libraries nsbundle ios
我正在Static Library为iOS应用程序创建一个.我几乎完成了它,但是资源存在问题.
我的静态库使用了大量的图像和声音文件.如何使用我的静态库传输它?
我知道我们可以将它包装在一个包上并沿着.a文件提供它.但我不知道如何将图像和声音文件包装在Bundle文件中.
我做了什么:
Settings Bundle.使用多个捆绑包和几种不同的方法来构建应用程序有几个很好的理由.根据我的经验,最好的方法是打开Xcode并创建一个新的捆绑项目:
示例:
// Static library code:
#define MYBUNDLE_NAME @"MyResources.bundle"
#define MYBUNDLE_IDENTIFIER @"eu.oaktree-ce.MyResources"
#define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME]
#define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH]
// Get an image file from your "static library" bundle:
- (NSString *) getMyBundlePathFor: (NSString *) filename
{
NSBundle *libBundle = MYBUNDLE;
if( libBundle && filename ){
return [[libBundle resourcePath] stringByAppendingPathComponent: filename];
}
return nil;
}
// .....
// Get an image file named info.png from the custom bundle
UIImage *imageFromMyBundle = [UIImage imageWithContentsOfFile: [self getMyBundlePathFor: @"info.png"] ];
Run Code Online (Sandbox Code Playgroud)
如需更多帮助,您可以查看这些好文章
希望它能帮到你.
| 归档时间: |
|
| 查看次数: |
7673 次 |
| 最近记录: |