iOS development: How to reduce the size of your application

Source: Internet
Author: User
Tags valid zip

Q: How to make my program installation package smaller, so that the download and installation of the program faster?

A: This article collects some tips for reducing the size of the program installation package (when downloading and installing the program for the first time). If this is for the upgrade program, you can read this article (reduce the size of the download required when the iOS app is upgraded) (this is different from how the first installation works).

Checking applications

First, check. App bundle, look at the files in the package which occupy the most space.

Before doing any related optimizations, we need to make some trade-offs. By weighing, you can know where to focus your optimization. We also need to consider some of the technical shortcomings mentioned in this article, and we must consider the relevant impact to ensure that the right decisions are made. Without a trade-off, we don't know what changes need to be made to the program.

When you first install the iOS program, you need to download a full. IPA file. (Note that this is different from the upgrade). In fact, the IPA document is a. zip structure.

We can use this method to find out the program's. IPA files: Download apps from the App Store, then use ITunes to synchronize iOS devices, and then view the directory: ~/music/itunes/itunes music/mobile Applications, you can find the. IPA document.

We can also construct the. IPA file by using the Xcode Archive command, which is basically consistent with the format submitted to the App Store.

Check. IPA documents

Simply modify the suffix of. ipa file to. zip, and then extract it using the Finder. Right-click on the extracted. App Bundle, select Display package content to view the resource files inside. By this method we can see which files occupy the most space. Remember: The app bundle is compressed, and some files have a better compression effect than other files, so the effect of compression is the most important. In general, however, the largest file before compression is still the largest file after compression. We can delete a file, then right-click in the Finder, and choose Compression, which allows more accurate measurements of the file compression effect.

IOS App Store related factors

The executable file that was submitted to the app in the App store was added to the encryption. The side effect of encryption is that the compression effect of the executable file is not as good as before, because encryption hides some details. Therefore, the size of the. IPA file downloaded from the App Store is larger than the. IPA file that was created locally.

Note: Removing long text content and table data from your code and adding it to an external file can reduce the size of the final installation package download-because the files are more compressed.

If you choose a archived in Organizer window, then click Estimate Size,xcode can make an assessment of the final distribution of the program size. This does not take into account the iOS program above the Mac App Store and the enterprise-level deployment.

Build Settings

Compilation options

Set the optimization level in build setting to fastest, smallest [-os]; Set the STRIP Debug symbols During COPY in build setting to Yes (Copy_phase_strip = yes) to reduce the size of the compiled binaries. The settings mentioned here are the default for release configurations in the Xcode project.

Warning: These settings will make your program difficult to debug. This setting is not recommended in the general development environment build.

Target is for fewer CPUs

By default, the Xcode project is configured to optimize the specific CPU type specified by the program to produce an executable file that is relative. Different hardware, will run different executable code. Although this optimized program can only run against certain devices, this greatly reduces the size of the executable program.

To set only a specific type of CPUs, you can modify the architectures in build setting from STANDARD $ (archs_standard) to the corresponding specific type of CPU in the list you want to support. Valid CPU names are listed in the VALID Architectures (VALID_ARCHS) build setting. Do not modify valid architectures settings, preferably managed by Xcode.

Assets

Perform an integrity check on the application

Use the process described in the inspecting Your app to make a comprehensive review of the. App bundle to understand what is really needed. In a program, you will often include additional files, such as the Readme, which will never be used.

Split the data out of the code

Stripping all resources (such as long strings) from your code and depositing them in an external file reduces the size of the final file downloads because they are better compressed. (Refer to the full description in the iOS app Store specific considerations.) )

Image Assets

Try to use 8-bit pictures

Using 8-bit's PNG pictures, you can reduce the compression rate by 4 times times more than 32-bit pictures. Since 8-bit's pictures support up to 256 different colors, 8-bit's pictures should generally only be used for a small portion of the color picture. For example grayscale pictures are best to use 8-bit.

Use a high compression ratio for 32-bit pictures

Use Adobe Photoshop's save for Web to reduce the size of JPEG and PNG pictures. In Xcode, by default, Pngcrush is used automatically to compress. png pictures.

Audio Assets

Compression of audio

The

Reference WWDC in audio Development for Games, which describes how to effectively process audio. In general, we use AAC or MP3 to compress audio, and we can try to reduce the bit rate of audio. Sometimes 44.1khz sampling is not necessary, and a slightly lower bit rate does not degrade audio quality.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.