IOS development: How to Reduce the application size

Source: Internet
Author: User

IOS development: How to Reduce the application size

Q: How can I reduce the installation package of my program and make it faster to download and install the program?

A: I have collected some tips on how to reduce the installation package size (when the program is downloaded and installed for the first time ). If you want to upgrade the app, read this article (reduce the download size required for iOS app upgrade) (This works differently from the first installation ).

Check applications

First, check the. app bundle to see which files in the package occupy the largest space.

We need to make some trade-offs before doing any related optimization. By balancing, you can know where the optimization focuses. We also need to consider some technical disadvantages mentioned in this Article. We must consider the impact to ensure that the correct decision is made. Without consideration, we cannot know what changes need to be made to the program.

When installing the iOS program first, you need to download the complete. ipa file. (Note that this is different from the upgrade ). Upload the. IPA file to a. ZIP file.

We can use this method to find out the. ipa file of the program: Download the App from the App Store, use iTunes to synchronize the App to the iOS device, and then view the Directory :~ /Music/iTunes Music/Mobile Applications, you can find the. ipa file.

You can also use the Archive command of Xcode to construct the. ipa file. The file format is basically the same as that submitted to the App Store.

Check the. ipa File

Simply change the suffix ".ipa" to ".zip" and decompress it using the Finder. Right-click the unzipped. app bundle and select Show Package content to view the resource files. By using this method, we can see which files occupy the largest space. Remember:. app bundle is compressed, and the compression effect of some files is better than that of other files, so the compression effect is the most important. However, the largest file before compression is usually the largest file after compression. You can delete a file, right-click it in the Finder, and select compress to more accurately measure the File compression effect.

Factors Related to iOS App Store

The executable files submitted to the App Store are encrypted. The side effect of encryption is that the compression effect of executable files is not as good as before, because encryption will hide some details. Therefore, the size of the. ipa file downloaded from the App Store is larger than that of the. ipa file built locally.

Note: Remove long text content and table data from the code and add it to an external file, which can reduce the size of the final installation package download-because these files are better compressed.

If you select an archived in the Organizer window and click Estimate Size, Xcode can evaluate the final distribution program Size. IOS programs deployed on Mac App Store and enterprise-level are not considered here.

Build Settings

Compilation options

Set the Optimization Level in build setting to Fastest, Smallest [-OS]; Set Strip Debug Symbols During Copy in build setting to YES (COPY_PHASE_STRIP = YES ), this reduces the size of the compiled binary file. The settings mentioned here are default for the Release configuration in the Xcode project.

Warning these settings make debugging difficult for your program. This setting is not recommended in General Development Environment build,

Target targets fewer CPUs

By default, Xcode projects are configured to optimize the Specific CPU type specified by the program to generate executable files. Different hardware will run different executable code. Although the optimized program can only run on some devices, this greatly reduces the size of the executable program.

To set only the CPUs of a specific type, you can modify the ubuntures in build setting and change it from Standard $ (ARCHS_STANDARD) to the corresponding type of CPU in the list you want to support. Valid CPU names are listed in Valid ubuntures (VALID_ARCHS) build setting. Do not modify the Valid ubuntures settings. It is best to manage them by Xcode.

Assets

Perform an integrity check on the Application

Use the process described in Inspecting Your App to perform a comprehensive check on. app bundle to understand what is actually needed. In a program, some additional files, such as readme, are often included, which are never used.

Extract data from code

Remove all resources (such as long strings) from the code and store them to external files. This reduces the size of the final File Download because these files are better compressed. (Refer to the complete introduction in iOS App Store Specific Considerations .)

Image Assets

Use an 8-bit image whenever possible

8-bit PNG images can reduce the compression ratio by 4 times than 32-bit images. Because 8-bit images support up to 256 different colors, 8-bit images are generally used only for a small part of the color. For example, it is best to use 8-bit for Grayscale Images.

Try to use a high compression ratio for 32-bit Images

Save For Web in Adobe Photoshop can reduce the size of JPEG and PNG images. In xcode, pngcrushis automatically used to compress .png images.

Audio Assets

Audio Compression

See Audio Development for Games in WWDC, which describes how to effectively Process Audio. In general, we need to use AAC or MP3 to compress the audio and try to reduce the bit rate of the audio. Sometimes 44.1khz sampling is unnecessary, and a slightly lower bit rate will not reduce the 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.