iOS app launch time measurement

后端 未结 6 1790
醉梦人生
醉梦人生 2021-02-15 17:19

How can I count the time it takes from the moment the user presses the launch button on the home screen until the moment the app is active (for example, until the viewDidAppear

6条回答
  •  庸人自扰
    2021-02-15 18:06

    A simple implementation is to start a StopWatch in the applications main and then grab the time result in the ViewDidAppear method:

    public class Application
    {
        public static Stopwatch StartUpTimer;
    
        static void Main(string[] args)
        {
                StartUpTimer = new Stopwatch();
                StartUpTimer.Start();
                UIApplication.Main(args, null, "AppDelegate");
        }
    }
    
    public class MyUIViewController : UIViewController
    {
        public override void ViewDidAppear (bool animated)
        {
    
            Console.WriteLine (Application.StartUpTimer.ElapsedMilliseconds.ToString () + "ms to startup");
            base.ViewDidAppear (animated);
        }
    }
    

提交回复
热议问题