簡體   English   中英

使用素材資源庫,iPhone和iPad之間的行為不同

[英]Different behavior between iPhone and iPad with the Assets Library

我在應用程序上使用資產庫枚舉設備的照片事件。

當我在iPad上進行測試時,我的代碼工作正常。 圖片活動已枚舉,我可以完美地處理它們。 當我在iPhone上嘗試相同的代碼時,什么也沒發生(並且我在此設備上也有“照片事件”)。 看起來好像沒有調用枚舉代碼(即,控制台中沒有日志出現,參見代碼)。

這是代碼:

- (void)loadEvents {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupEvent
                           usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                               if (group) {
                                   [photosEventsArray addObject:group];
                                   NSLog(@"Adding group");
                               } else {
                                   NSLog(@"End of the enumeration");
                               }
                           }
                         failureBlock: ^(NSError *error) {
                     NSLog(@"Failure while enumerating assets: %@", error);
                         }];
    [library release];

    NSLog(@"Found %d events", photosEventsFound);

    [self performSelectorOnMainThread:@selector(stopSpinner) withObject:nil waitUntilDone:YES];
    [pool drain];
}

我的部署目標是iOS 4.1。

對這里出什么問題有任何想法嗎?

經過更多調查,似乎在iOS 4.3.5上,從主線程調用了enumerateGroupsWithTypes方法。

我已經用這種方式修補了代碼(在iPhone和iPod Touch中設置為“否”,在iPad中設置為“是”):

if (scanAssetsInBackground) {
    [self performSelectorInBackground:@selector(loadEvents) withObject:nil];
} else {
    [self performSelectorOnMainThread:@selector(loadEvents) withObject:nil waitUntilDone:YES];
}

該補丁可以正常工作。

Apple文檔中對此沒有太多信息,也沒有辦法知道哪種方法(后台線程或主線程)是掃描資產庫的正確方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM