简体   繁体   English

Cocoa Mac OS X 应用程序捆绑 1000 个图像

[英]Cocoa Mac OS X application bundling 1000 images

We have a Cocoa Mac OS X application in which we want to bundle around 500 images.我们有一个 Cocoa Mac OS X 应用程序,我们希望在其中捆绑大约 500 个图像。 Each image is around 10kb so size isn't a problem.每个图像大约 10kb,所以大小不是问题。

These images are not exactly resources in the app, they are sample images.这些图像不完全是应用程序中的资源,它们是示例图像。

Basically, we have simple button that would let the user copy these images to a directory.基本上,我们有一个简单的按钮,可以让用户将这些图像复制到一个目录中。

The solution also needs to be "dump in, dump out" -- so we don't want to store individual image file names somewhere in our application;解决方案也需要“转储,转储”——所以我们不想在我们的应用程序的某个地方存储单个图像文件名; we just want to have a directory of images that can be copied.我们只想有一个可以复制的图像目录。

How do I package these into my application?我如何将这些打包到我的应用程序中?

The question turns into: How do I make a directory resource containing the images.问题变成:如何制作包含图像的目录资源。

In our case everything gets flattened into the MyApp.app/Contents/Resources and this approach would require us to put image names in the app so that we can copy those.在我们的例子中,一切都被压缩到 MyApp.app/Contents/Resources 中,这种方法需要我们将图像名称放在应用程序中,以便我们可以复制它们。

Put the images into a folder.将图像放入文件夹。 Drag the folder into your project in Xcode.在 Xcode 中将该文件夹拖到您的项目中。 In the resulting dialog, make sure you copy, make sure you create a folder reference , and make sure you add to your app target.在结果对话框中,确保复制,确保创建文件夹引用,并确保添加到应用程序目标。 Done.完毕。 Now the folder is part of your app bundle and you can refer to it from your code without knowing anything about its contents.现在该文件夹是您的应用程序包的一部分,您可以在不了解其内容的情况下从代码中引用它。

The folder /Library/Application Support is for support files that, if deleted, would not affect the execution of an application.文件夹/Library/Application Support用于存放支持文件,如果删除这些文件,则不会影响应用程序的执行。 I would suggest this is ideal for your product's sample images.我建议这非常适合您产品的示例图像。

As Apple's documentation states for Application Support :正如Apple 的Application Support 文档所述:

Use this directory to store all app data files except those associated with the user's documents.使用此目录存储除与用户文档相关联的应用程序数据文件之外的所有应用程序数据文件。 For example, you might use this directory to store app-created data files, configuration files, templates, or other fixed or modifiable resources that are managed by the app.例如,您可以使用此目录来存储应用程序创建的数据文件、配置文件、模板或由应用程序管理的其他固定或可修改资源。 An app might use this directory to store a modifiable copy of resources contained initially in the app's bundle.应用程序可能会使用此目录来存储最初包含在应用程序包中的资源的可修改副本。

So, use pkgbuild / productbuild to install them to /Library/Application Support/<ProductName>/因此,使用pkgbuild / productbuild将它们安装到/Library/Application Support/<ProductName>/

因为大小不是问题,您可以将所有示例图像放在单独的资产目录文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM