我目前正在开发iOS应用程序。我需要比较在iPhone和/或iPad上启动所需的时间。有人可以建议吗?
最佳答案
记下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
}
关于iphone - 如何检查iPhone应用程序启动所需的时间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10402932/