将 iPhone 应用程序文件大小控制在 10.0MB 以下有哪些好的指导原则?

发布于 2024-07-21 04:50:45 字数 136 浏览 6 评论 0原文

我希望将我的应用程序保持在 10.0MB 以下,以便在蜂窝网络和 Wifi 网络环境中轻松下载。 根据您的经验,您是否遇到过任何保持应用程序精简的好方法? 如果有请分享。 将 iPhone 应用程序文件大小控制在 10.0MB 以下有哪些好的指导原则?

I want to keep my app under 10.0MB for easy downloading in both cellular and Wifi network environments. In your experience have you come across any good ways for keeping your apps slim? If so please share. What are some good guidelines for keeping iPhone app file-size under 10.0MB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

听闻余生 2024-07-28 04:50:45

我处理过的大多数超过 10M 的应用程序都是由于资源(通常是图像和音频)造成的。 正确调整它们的大小至关重要。 请注意,iPhone 在为设备捆绑时会自动进行一些压缩,因此模拟器中的内容大小可能与设备上的大小完全不同。

与所有优化练习一样,您希望首先构建一个可靠、健全的系统,然后将优化工作集中在导致最大问题的部分上。 我使用 du 来实现此目的:

  • 在 Release 中构建设备
  • 转到 build/Release-iphoneos/.app
  • du -ak | 排序-rn | head

这将为您提供最重要的内容的列表。 此信息以 kB 为单位,但会向上舍入到下一个块(在 Mac 上为 4k)。 但你只是在寻找大的东西,而不是计算出所有东西的确切尺寸。

特别注意那些不应该复制到您的资源中的内容。 有时会出现一些有趣的东西,尤其是您添加到项目中的文档。 对此进行测试,我注意到我自己的项目模板已将 xcconfig 文件复制到捆绑包中(必须修复该问题...)

如果您有大量本地化的 NIB,那么您可能需要考虑不本地化 NIB,而使用 IBOutlet UI 标签。 如果没有实际的本地化文本,请勿本地化 NIB。 仅仅本地化一个 NIB 并不意味着您必须本地化所有它们。

一般来说,iPhone 的构建设置已经在缩小尺寸方面非常积极,所以在不研究你要更改的内容之前我不会对此进行太多改动。

请注意 Objective-C 类,其中包含许多您从未调用过的方法。 Objective-C 是动态的,因此您不能像 C 那样对其进行死代码剥离。在编译时无法知道选择器是否可以在运行时使用。 因此,如果您的物品中带有厨房水槽“以防万一”,您可能需要将其拆除。 但一般来说,与单个音频文件相比,我们在这里讨论的空间并不是很大。 我只在极少数情况下提到它,即您有一个非常大的对象,您仅链接某些类方法或常量等。

Most apps I've dealt with that go over 10M are due to resources, often images and audio. Correctly sizing these them is critical. Note that iPhone does some compression for you automatically when bundling for the device, so the size of things in Simulator can be radically different than on device.

Like all optimization exercises, you want to build a solid, sane system first and then focus your optimization efforts on the pieces that are causing the biggest issues. I use du for this:

  • Build for the device in Release
  • Go to build/Release-iphoneos/.app
  • du -ak | sort -rn | head

This will give you a list of where the top things are. This information is in kB, but is rounded up to the next block (4k on Mac). But you're just looking for what's big, not working out the exact size of everything.

Look especially for things being copied into your Resources that shouldn't be. Funny things sometimes get in there, especially documentation that you've added to the project. Testing this out, I notice that my own project template has been copying xcconfig files into the bundle (gotta fix that...)

If you have lots of localized NIBs, then you may want to consider not localizing the NIBs, and rather using IBOutlet UILabels. Don't localize a NIB if there's no actual localized text. Just because you localize one NIB doesn't mean you have to localize all of them.

Generally the build settings for iPhone are already aggressive in getting the size down, so I wouldn't mess with that a lot without researching what you're changing.

Do watch out for Objective-C classes with many methods that you never call. Objective-C is dynamic, so you can't do dead-code stripping on it like in C. There's no way to know at compile time whether a selector might be used at run-time. So if you have objects that have the kitchen-sink in them "just in case," you may want to strip those down. But generally we're not talking about a lot of space here compared to a single audio file. I only mention it for the rare case where you have a really huge object that you only link for some class method or constant or the like.

戏舞 2024-07-28 04:50:45

另一个提示:小心使用 9.9MB 的应用

您不想在经过大量优化后发现您的应用程序看起来只有 10.1MB。

Another tip: Be careful with your 9.9MB app!

You don't want to discover after lots of optimizations that your app appears to be 10.1MB.

熟人话多 2024-07-28 04:50:45

一种技巧是使用压缩媒体格式。 例如,如果您使用音频文件,您可以考虑使用 mp3 而不是 AIFF 或 WAV,但处理开销可能会稍高一些。 10mb 的可执行文件听起来异常高,因此这么大的应用程序可能会包含大量媒体内容(图像、音频)。

One tip would be to use compressed media formats. E.g. if you are using audio files you could consider using mp3 instead of AIFF or WAV, at the possible price of a slightly higher processing overhead. A 10mb executable sounds unusually high so maybe an app that big would contain a lot of media content (images, audio).

一人独醉 2024-07-28 04:50:45

如果您的一些较大图像适合您的应用程序的外观,请将其转换为灰度图像。 如果你能制作一些纯灰度的,节省的费用是相当可观的。

Convert a few of your larger images to grayscale if it will work with your app's look. If you can make a few purely grayscale, the savings is pretty substantial.

猛虎独行 2024-07-28 04:50:45

构建过程会自动为您压缩 PNG 文件(使用 pngcrush,不要自己执行此操作),因此实际上您必须拥有相当多的资源才能获得超过 10MB 的大小。 我认为担心这是一个过早的优化,你可能不需要担心,直到你发现自己稍后接近。

The build process automatically compressed PNG files for you (using pngcrush, do not do that yourself), so actually you'd have to have quite a lot of assets to get over 10MB is size. I think worrying about this is a premature optimization and you probably do not need to be concerned until you find yourself getting close later.

风和你 2024-07-28 04:50:45

此技巧主要适用于 iPhone 游戏:

  • 对于不透明的图像,请使用 JPG 而不是 PNG。
  • 将声音保存为 mp3 格式,首先将它们渲染为 WAV加载应用程序并将其保存到应用程序文档目录中。

This tipos will mostly apply to iPhone games:

  • Use JPGs instead of PNGs for images that don't have transparency.
  • Have your sounds in mp3, render them to WAV the first time the app is loaded and save them to the app Documents dir.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文