Latest 1.3.4
Homepage https://github.com/junyixie/AppStartTime
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

AppStartTime is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'AppStartTime'

思路

iOS 使用RunLoop来确定首屏渲染时间的方案

既然在 didFinishLaunchingWithOptions 所在runloop的末尾,会主动调用CA::Transaction::commit完成视图的渲染, 那么,可以找一个恰当的时机插入我们的代码,来记录当时的时间。
didFinishLaunchingWithOptions 和 viewDidAppear 等一系列方法的执行都是 source0 事件,当source0事件执行完毕后去执行source1事件(如果有),timer 事件属于source1事件源。

根据runloop的内部逻辑,我们可以插入一个timer事件源,在处理完source0后会去执行我们的timer事件。此时记录时间是相当准确的。

2018-02-21 21:17:48.991167+0800 AppStartTime_Example[25922:3193890] BeforeTimers
2018-02-21 21:17:48.991262+0800 AppStartTime_Example[25922:3193890] BeforeSources
2018-02-21 21:17:49.046089+0800 AppStartTime_Example[25922:3193890] didFinishLaunchingWithOptions
2018-02-21 21:17:49.055713+0800 AppStartTime_Example[25922:3193890] viewdidload
2018-02-21 21:17:49.062093+0800 AppStartTime_Example[25922:3193890] didlayoutsubviews
2018-02-21 21:17:49.062508+0800 AppStartTime_Example[25922:3193890] draw rect
2018-02-21 21:17:49.064032+0800 AppStartTime_Example[25922:3193890] viewDidAppear
2018-02-21 21:17:49.064291+0800 AppStartTime_Example[25922:3193890] AppstartTime 首屏渲染记录
2018-02-21 21:17:49.064917+0800 AppStartTime_Example[25922:3193890] BeforeTimers
2018-02-21 21:17:49.065049+0800 AppStartTime_Example[25922:3193890] BeforeSources

时间的误差就被锁定在一个runloop之内了。

Author

junyixie, [email protected]

Some Code Reference

Joy_HookLoad

everettjf_HookCppInitilizers

License

AppStartTime is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "AppStartTime",
    "version": "1.3.4",
    "summary": "A short description of AppStartTime.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/junyixie/AppStartTime",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "junyixie": "[email protected]"
    },
    "source": {
        "git": "https://github.com/junyixie/AppStartTime.git",
        "tag": "1.3.4"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "AppStartTime/Classes/**/*"
}

Pin It on Pinterest

Share This