AlAssetsGroup枚举需要很长时间才能启动大型组

时间:2013-01-16 22:53:46

标签: ios alassetslibrary

当ALAssetsGroup很大时,在调用enumerateAssetsUsingBlock:或enumerateAssetsAtIndexes:以及调用第一个枚举块的时间之间会有几秒的延迟。

在库中有10000个资产的iPad 2上,此延迟大约是调用第一个资产块之前的4.2秒。

具有相同库的同一设备上的Photos.app在不到一秒的时间内启动,显示库中的所有照片。我不知道它是怎么做到的。这就是我们希望看到的那种行为。

这是一个显示行为的最小测试用例:

ALAssetsLibrary* assetLibrary = [ALAssetsLibrary new];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupLibrary
                            usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     if (group != nil) {
         NSLog(@"*** Got library group, start timer");
         NSDate* tic = [NSDate date];

         [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
          {
              if (result==nil) {
                  NSLog(@"*** Elapsed time to final enumeration: %.2fs", -[tic timeIntervalSinceNow]);
              }
              else if (index==0) {
                  NSLog(@"*** Elapsed time to image 0: %.2fs", -[tic timeIntervalSinceNow]);
              }
          }];

         *stop = YES;
     }
 }
                          failureBlock:^(NSError *error)
 {
     NSLog(@"ERROR: %@", [error localizedDescription]);
 }];

输出:

*** Got library group, start timer
*** Elapsed time to image 0: 4.20s
*** Elapsed time to final enumeration: 4.20s

(请注意,此(稍有不同)问题中接受的解决方案不起作用。延迟发生在第一个资产到达之前:Possible ways to speed up reading from ALAssetsLibrary and populating a UITableView

0 个答案:

没有答案