如何在 Xcode 中为 iPhone 应用程序创建我自己的包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2578496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:15:40  来源:igfitidea点击:

How to create my own bundle in Xcode, for iPhone application

iphoneobjective-cxcodefacebookbundle

提问by Sagar R. Kothari

I am having some difficulty creating a bundle for my application, and placing files in the bundle.

我在为我的应用程序创建包并将文件放入包中时遇到了一些困难。

For example, Facebookhas developed a bundle for iPhone applications using their framework. In the same way, I also want to create a bundle which can be reused for many applications.

例如,Facebook使用他们的框架为 iPhone 应用程序开发了一个包。同样,我也想创建一个可以为许多应用程序重用的包。

My questions are:

我的问题是:

  • what steps should I follow to create a bundle for any kind of application?
  • what should be taken care while creating a bundle?
  • 我应该遵循哪些步骤来为任何类型的应用程序创建包?
  • 创建捆绑包时应该注意什么?

回答by Felixyz

First of all, since your question is tagged iPhone, you can only include code in your bundles on the iPhone. So basically you can only use bundles to package up pictures and sound files and other static data.

首先,由于您的问题被标记为 iPhone,您只能在 iPhone 上的捆绑包中包含代码。所以基本上只能用bundle来打包图片和声音文件等静态数据。

When you create a new project in XCode, there is an option to make the target a bundle (under Framework & Library), but an assets bundle is just a directory with a .bundle suffix. I generate mine with this little script:

当你在 XCode 中创建一个新项目时,有一个选项可以让目标成为一个包(在框架和库下),但资产包只是一个带有 .bundle 后缀的目录。我用这个小脚本生成我的:

#!/bin/bash
echo "Building assets bundle."
if [ -d ./MyAssets.bundle ]; then
   rm ./MyAssets.bundle/*
else
   mkdir ./MyAssets.bundle
fi
find ./assets -type f -print0 | xargs -0 -J% cp % ./MyAssets.bundle

(I'm no bash hacker, so this can probably be improved in countless ways. Suggestions welcome!)

(我不是 bash 黑客,所以这可能可以通过无数方式改进。欢迎提出建议!)

This takes a folder hierarchy and flattens it (I detest hierarchies) into a single directory which is named MyAssets.bundle. I trigger this script from a separate build phase when in projects that import the bundle, so that changes are automatically tracked.

这需要一个文件夹层次结构并将其展平(我讨厌层次结构)到一个名为 MyAssets.bundle 的目录中。在导入包的项目中,我从单独的构建阶段触发此脚本,以便自动跟踪更改。

If you want to learn how to create framework bundles, it's a bit more complicated (you have to follow certain conventions and include info in plists), but for iPhone bundles, this is pretty much all you will need to know and do.

如果你想学习如何创建框架包,它有点复杂(你必须遵循某些约定并在 plist 中包含信息),但对于 iPhone 包,这几乎是你需要知道和做的全部。

回答by Luis Ascorbe

You could do this too:

你也可以这样做:

Make a folder in finder, add files to it, rename it to bundlename.bundle

在finder中创建一个文件夹,向其中添加文件,将其重命名为bundlename.bundle

drag into Xcode - success!

拖入 Xcode - 成功!

to access, use the form of PathToMainBundle+"/bundlename.bundle"

访问,使用PathToMainBundle+"/bundlename.bundle"的形式

Source: https://stackoverflow.com/a/5277452/736384

来源:https: //stackoverflow.com/a/5277452/736384