PhotoKit: сбой fetchAssetCollectionsWithLocalIdentifiers

Следующий код выделяет проблему в 3 простых шага:

1) ловить моменты

2) момент кеша localIdentifier

3) получить момент с идентификатором: сбой (на устройстве, iOS 8.2)

- ( void )momentLocalIdTest
{
    PHFetchResult       * fetchResult;
    PHAssetCollection   * moment;
    NSString            * localIdentifier;

    fetchResult = [ PHAssetCollection fetchMomentsWithOptions: nil ];

    if( fetchResult.count == 0 )
        return;

    moment          = fetchResult.firstObject;
    localIdentifier = moment.localIdentifier;
    fetchResult     = [ PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers: @[ localIdentifier ] options: nil ];

    if( fetchResult.count == 0 )
        NSLog( @"AssetCollection with localIdentifier %@ not found!!!", localIdentifier );
}

Я что-то неправильно понимаю? Вроде все просто...

Любая помощь приветствуется!


person Gregzo    schedule 26.03.2015    source источник
comment
Подал отчет об ошибке 20307335.   -  person Gregzo    schedule 27.03.2015
comment
Отчет об ошибке является дубликатом известной проблемы.   -  person Gregzo    schedule 20.04.2015


Ответы (1)


Я тоже столкнулся с той же проблемой и не мог понять, что не так с этим кодом. Я думаю, что этот API просто и просто сломан (по крайней мере, с 8.0 по 8.4)

Вот обходной код; вам в основном нужно возродить экземпляр PHAssetCollection из идентификатора

PHFetchOptions *options = [PHFetchOptions new];
options.predicate = [NSPredicate predicateWithFormat:@"localIdentifier = %@", identifier];

PHAssetCollection *collection = [[PHAssetCollection fetchMomentsWithOptions:options] firstObject];
PHFetchResult *results = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
person Olotiar    schedule 23.07.2015