gpt4 book ai didi

ios - How to transfer resource files with Static Library (How to wrap resources in bundle)?

转载 作者:可可西里 更新时间:2023-11-01 03:09:04 25 4
gpt4 key购买 nike


我正在为 iOS 应用程序创建一个静态库。我快完成了,但是资源有问题。

我的静态库使用了大量图像和声音文件。如何将它与我的静态库一起传输?

我知道我们可以将其打包并与 .a 文件一起提供。但我不知道如何将图像和声音文件包装在 Bundle 文件中。

我做了什么:

  • 我搜索了很多,但找不到任何有用的链接。
  • 我得到了 Conceptual CFBundles引用,但没有找到解决我的问题的方法。
  • 我检查了可用于 XCode 的文件模板,但没有看到除 Settings Bundle 之外的任何包类型。

最佳答案

有几个很好的理由来构建具有多个 bundle 的应用程序和几种不同的方法。根据我的经验,最好的方法是打开 Xcode 并创建一个新的 bundle 项目:

  1. 选择:文件 -> 新项目... -> Mac OSX (!) -> Framework & Library -> Bundle。将您的资源文件添加到项目中。
  2. 在构建其他 iPhone 应用程序时构建 bundle 。
  3. 您可以将这个项目添加到您的静态库项目中,并在库发生变化时重新构建它。您必须知道 bundle 本身不会链接到您的库文件。
  4. 在您的应用程序项目中,将 .bundle 文件作为普通资源文件添加到您的项目中(添加 -> 现有文件... -> 找到并选择上面构建的 .bundle 文件。不要复制它)。

示例:

// 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"] ];

更多帮助你可以查看这些好文章

  1. iOS Library With Resources

  2. Resource Bundles

希望对你有帮助。

关于ios - How to transfer resource files with Static Library (How to wrap resources in bundle)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16297696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com