How to calculate iOS app boot time

て烟熏妆下的殇ゞ 提交于 2019-12-31 02:35:07

问题


I was wondering if there is a quick and efficient way to determine the Time from opening an app to when it's fully loaded.

  • I was thinking I'd do something like get an NSDate object in didFinishLaunchingWithOptions and get another in my UIViewController, then compare them.
  • However, I'm not sure that would be completely accurate. Is there a better way to do this?

回答1:


That really won't work because it doesn't deal with iOS loading and launching your app.

The best you should do is log a timestamp in main but again, this won't include the time it takes iOS to load and launch the app to the point that main is called.

Any timing you do will be from that point forward which may still be useful depending on your goal.




回答2:


Keep a NSUserDefaults value to count the run time of the app in your didFinishLaunchingWithOptions or applicationDidBecomeActive method:

int i = [[NSUserDefaults standardUserDefaults] integerForKey:@"usageCount"];
i = i+1;
[[NSUserDefaults standardUserDefaults] setInteger:i forKey:@"usageCount"];
[[NSUserDefaults standardUserDefaults] synchronize];


来源:https://stackoverflow.com/questions/23349570/how-to-calculate-ios-app-boot-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!