2012-05-01 165 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

相關問題