Comprehensive Guide to Reducing iOS App Package Size
This article presents a step‑by‑step guide for shrinking iOS app IPA size by leveraging App Thinning, removing unused image assets, compressing media, and eliminating dead code through tools like FengNiao, LSUnusedResources, AppCode, and LinkMap analysis.
Introduction
The author has iterated an iOS app through nearly 20 versions without ever optimizing the IPA size, reducing the package from 89 MB to 75 MB by applying a series of size‑reduction techniques.
Background and Problem
App Store limits OTA downloads to 200 MB, and the binary text segment must stay under 60 MB for iOS 7/8 compatibility; exceeding these limits can prevent Wi‑Fi‑only downloads and even block App Store submission, making size control critical.
Analysis and Positioning
Growth in codebase and resources leads to bloated packages; the article explores official App Thinning, removal of unused images, media compression, and code slimming as primary mitigation strategies.
Official App Thinning
App Thinning reduces the installed size by delivering only the resources needed for the target device.
It consists of three processes: Slicing , Bitcode , and On‑Demand Resources (ODR) .
3.1 Slicing
Slicing selects device‑specific assets (e.g., 2× images for iPhone 6, 3× for iPhone 6 Plus) during build and distribution.
Configure assets in Xcode Asset Catalog.
Build and run on the target device to generate a simplified app.
Upload to App Store Connect; TestFlight delivers the appropriate slice.
3.2 Bitcode
Bitcode stores an intermediate representation of the compiled binary; Apple can re‑optimize the binary without a new upload.
3.3 On‑Demand Resources
ODR allows downloading resources only when needed, reducing initial install size.
Removing Unused Images
Identifying and deleting unused image assets can immediately shrink the package.
Methods include manual search, the open‑source tool FengNiao , and LSUnusedResources (recommended).
4.1 Workflow
Use find /Users/zhang**/Project/ -name to list all resource files.
Define target extensions (jpg, gif, png, webp).
Match resource names in source code with a regex, e.g., pattern = @"(.+?)" .
Subtract used resources from the full list to obtain unused assets.
Adjust regex rules for patterned names (e.g., @"image_%d" ).
Delete unused files via NSFileManager .
4.2 FengNiao
Install with:
git clone https://github.com/onevcat/FengNiao.gitRun ./install.sh to place the binary in /usr/local/bin . Use commands list , delete , and ignore to manage assets.
4.3 LSUnusedResources
Run the tool, configure matching rules, and visualize unused images; typically saves 3‑5 MB.
Image and Video Compression
After cleaning unused assets, further size reduction is possible by compressing remaining media.
5.1 Video Compression
Guide videos were reduced from 2‑3 MB each to under 1.3 MB, saving 4‑5 MB total.
5.2 Image Compression
Convert images to WebP using Google’s cwebp tool:
cwebp [options] input_file -o output_file.webpFor lossless compression:
cwebp -lossless original.png -o new.webpWebP offers high compression with visual parity; for files <100 KB, tools like TinyPNG or ImageOptim are recommended.
Code Slimming
The executable consists of resources and compiled code; reducing dead code further shrinks the IPA.
6.1 Using AppCode
Run Code → Inspect Code to list unused classes, methods, properties, macros, and globals. Manual verification is required for false positives (e.g., JSONModel protocols, dynamic selectors, NSClassFromString usage).
6.2 LinkMap & Mach‑O Analysis
Enable Write Link Map File = Yes in Xcode Build Settings. The generated LinkMap contains Object Files, Sections, and Symbols. By extracting __objc_selrefs , __objc_classrefs , and __objc_superrefs , one can identify used symbols and compute the difference to find dead code.
Tools like MachOView help visualize these sections, but dynamic Objective‑C calls may hide some usages, so manual confirmation remains essential.
Other Slimming Techniques
Clang/LLVM Optimization Flags
Use -Os (Fastest Smallest) for release builds to minimize binary size while preserving performance.
Swift Compiler Options
Swift’s newer optimization settings (post‑Xcode 9.3) further reduce binary size.
Team Practices & Tips
Avoid unnecessary third‑party libraries; replace heavy dependencies with custom lightweight code.
Consolidate UI components to reuse code.
Prefer functions over multi‑line macros.
Store images in Images.xcassets for automatic compression and device‑specific slicing.
Offload large non‑essential assets (fonts, skins) to be downloaded at runtime.
Conclusion
The article outlines a comprehensive set of strategies for shrinking iOS app packages, ranging from resource cleanup and media compression to dead‑code elimination and compiler optimizations, and emphasizes that the chosen approach should match the app’s size, codebase complexity, and release cadence.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.