我目前正在开发iOS应用程序。我需要比较在iPhone和/或iPad上启动的时间。有人可以建议吗?
答案 0 :(得分:1)
记下main()
和-application:didFinishLaunchingWithOptions:
中的当前时间,然后计算差异。例如:
的main.m:
// main.m
NSDate *startupDate;
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
startupDate = [[NSDate alloc] init];
int exitCode = UIApplicationMain(argc, argv, NULL, @"AppDelegate");
[startupDate release];
[pool drain];
return exitCode;
}
// etc.
AppDelegate.m:
// AppDelegate.m
extern NSDate *startupDate;
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opts
{
NSDate *launchFinishedDate = [[NSDate alloc] init];
NSTimeInterval launchTimeInSeconds = [launchFinishedDate timeIntervalSinceDate:startupDate];
[launchFinishedDate release];
// launchTimeInSeconds will contain the launch time in seconds (floating point).
// create UI setup etc. as usual
}
答案 1 :(得分:0)
您可以使用仪器(包含在Xcode中)和Time Profiler来监控您的应用程序的启动。