2012-05-01 169 views

回答

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 
} 
0

你可以使用工具(包含在Xcode)与时间探查器监视您的应用程序的启动。

+0

在模拟器上,但不在实际设备上。 – 2012-05-02 11:21:38

+0

您可以在模拟器和设备上执行此操作。 – pherediac

相关问题