1

我们的应用程序需要时间从 iPod 的后台恢复,所以它每次都显示启动画面。当应用程序进入前台时,它会从缓存中加载一些数据,如果有大量数据需要时间。我该如何处理这种情况?我只是将这些方法放入调度队列,但没有显着效果。

4

1 回答 1

1

使用调度队列并将那些耗时的方法(从缓存加载数据的方法)发送到后台。完成后,说您现在需要进行一些 UI 更新,获取主队列并在那里更新 UI

dispatch_queue_t queue = dispatch_queue_create("name for the queue", NULL);
dispatch_async(queue, ^{
    //your extensive code goes here, should not involve any UI updates
    //If there are any UI updates involved, uncomment the following code:
    /*dispatch_async(dispatch_get_main_queue(), ^{
        //UI update here, as it should always be done on main thread
    });*/
});

由于您在启动期间在主线程上进行大量计算,因此您将看到初始屏幕。您应该照顾好它并将其移至后台,因为将来,如果从缓存中加载需要很长时间,超过 10 秒,您的应用程序将被看门狗杀死。

干杯,玩得开心

于 2013-02-13T06:08:14.903 回答