Reducing iOS App Launch Time — Pre-Main Time
We have seen overview of app launch types, pre main time and post main time. If you are still not aware about these terms then please refer my first blog here.
if your app uses so many third party libraries or your app have combination of objective C and swift files then you might have encountered this problem.
Now it’s time to set up and reduce the pre main time of our app launch. Let’s see the ways to achieve reduction of pre main time.
- Using Cartage: we can reduce pre main time by changing all our dynamic libraries to static libraries. we can use cartage for this.
- Using CocoaPods : cocoapods 1.5 and above version supports to convert dynamic libraries to static libraries.
If your using CocoaPods please go through the steps mentioned below.
- Change use_frameworks! to use_modular_headers! in pod file.
use_modular_headers! will convert all of your pods to static libraries. you can change particular pod to static library using :modular_headers => true e.g: pod ‘Alamofire’, ‘~> 4.7’ :modular_headers => true
2. If your app is combination of Objective C and Swift files and you are using some of the objective c files in pod, then change the pre compile headers to NO
Note: This can be changed only if you are getting errors in third party libraries during compilation because of combination of Objective C and Swift files in Cocoa pod. This is applicable when you are trying to change the libraries to static otherwise you can skip this step.
Go to your project -> Build Settings -> Apple LLVM 6.0 Language
3. Change Mach-O type to Static in pod target under build setting.
Steps: go to Pods folder -> select Build Settings -> search for Mach-O type -> change Mach-O type to static Library
Note: Do not change Mach-O type under build setting in the project folder. No change is required in project folder e.g : Executable.
4. If your app is combination of Objective C and Swift files and you are using some of the objective c files in Cocoa pod, then change Other Linker Flag to -Objc
Steps: go to Pods folder -> select Build Settings -> search for Other Linker Flag -> change Other Linker Flag to -Objc
Now we end up with reducing app launch time but it increases our app bundle size because of static libraries.
3. Merging Third party libraries : We can reduce the app launch time by merging several third party frame work into one.
I would recommend you to watch the WWDC 2016 talk on Optimizing App Startup Time to know in detail which might affect pre-main time.
LAST REMARKS
I hope you have enjoyed and learned something valuable from my article. If you have then let me know by hitting that ❤ button and follow me on Medium.