Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 动态计算应用程序加载时间_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 动态计算应用程序加载时间

Iphone 动态计算应用程序加载时间,iphone,objective-c,xcode,Iphone,Objective C,Xcode,如何运行一个时钟来测量在appDidFinishLaunching之前的加载时间 我想设置一个睡眠呼叫,将Defaul.png的显示时间延长到3秒,而不管底层硬件的速度如何。首先,你应该知道iPhone操作系统中的Springboard对加载时间有点挑剔。您不应该在应用程序加载过程中的某个地方进行休眠调用。如果Springboard检测到您的应用程序启动时间过长,您的应用程序将在崩溃日志中以“未能及时启动”终止 - (void)applicationDidFinishLaunching:(UIA

如何运行一个时钟来测量在appDidFinishLaunching之前的加载时间


我想设置一个睡眠呼叫,将Defaul.png的显示时间延长到3秒,而不管底层硬件的速度如何。

首先,你应该知道iPhone操作系统中的Springboard对加载时间有点挑剔。您不应该在应用程序加载过程中的某个地方进行休眠调用。如果Springboard检测到您的应用程序启动时间过长,您的应用程序将在崩溃日志中以“未能及时启动”终止

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Create the image view posing with default.png on top of the application
    UIImageView *defaultPNG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
    // Add the image view top-most in the window
    [window addSubview:defaultPNG];

    [window makeKeyAndVisible];

    // Begin doing the time consuming stuff in the background
    [self performSelectorInBackground:@selector(loadStuff) withObject:nil];

    // Remove the default.png after 3 seconds
    [self performSelector:@selector(removeDefaultPNG:) withObject:defaultPNG afterDelay:3.0f];
}

- (void)removeDefaultPNG:(UIImageView *)defaultPNG {
    // We're now assuming that the application is loaded underneath the defaultPNG overlay
    // This might not be the case, so you can also check here to see if it's ok to remove the overlay
    [defaultPNG removeFromSuperview];
    [defaultPNG release];
}
其次,据我所知,没有一种方法可以测量应用程序启动所需的时间。当用户点击springboard上的应用程序图标时,会发生一些事情,而iPhone操作系统无法为您的应用程序提供良好的信息

一种解决方案是确保您的
应用程序的dFinishLaunching:
非常轻量级,并创建一个“假”Default.png覆盖。通过精简您的
applicationdFinishLaunching:
方法以仅执行最基本的工作,并在后台执行任何耗时的任务,您可以确保在不同硬件上大致相同的时间显示Default.png覆盖

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Create the image view posing with default.png on top of the application
    UIImageView *defaultPNG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
    // Add the image view top-most in the window
    [window addSubview:defaultPNG];

    [window makeKeyAndVisible];

    // Begin doing the time consuming stuff in the background
    [self performSelectorInBackground:@selector(loadStuff) withObject:nil];

    // Remove the default.png after 3 seconds
    [self performSelector:@selector(removeDefaultPNG:) withObject:defaultPNG afterDelay:3.0f];
}

- (void)removeDefaultPNG:(UIImageView *)defaultPNG {
    // We're now assuming that the application is loaded underneath the defaultPNG overlay
    // This might not be the case, so you can also check here to see if it's ok to remove the overlay
    [defaultPNG removeFromSuperview];
    [defaultPNG release];
}

如果在
loadStuff
方法中添加更多视图(视图控制器等),则应将它们插入defaultPNG覆盖的下方。您还应该注意从另一个线程执行这些操作时可能出现的问题。如果遇到问题,您可以使用
performSelectorOnMainThread:withObject:waitUntilDone:

您好,多亏了这一点,alleus读起来不错,但需要先处理一下,很快就会回来。