从照片库中获取图像时出错:[__ NSCFString objectID]:发送到实例

时间:2016-09-14 14:18:07

标签: ios objective-c nspredicate phasset phfetchoptions

我在使用NSPredicate提取图像以过滤匹配的图像名称时遇到问题。

代码在PHFetchReult *fetchResult崩溃。

错误信息是:

2016-09-15 00:51:25.112 PICTAG[1122:971448] -[__NSCFString objectID]: unrecognized selector sent to instance 0x14d89150
2016-09-15 00:51:25.114 PICTAG[1122:971448] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectID]: unrecognized selector sent to instance 0x14d89150'

我的代码是:

-(NSMutableArray *) getAllMatchingPhotos {
    NSMutableArray *matchingPhotos = [[NSMutableArray alloc]init];

    while(matchingPhotos.count != photos.count){
        int i = 0;
        PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
        fetchOptions.predicate = [NSPredicate predicateWithFormat:@"SELF == %@",[photos[i] valueForKey:@"keyFilePath"]];
        PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
        [matchingPhotos addObject:fetchResult];
        i++;
    }

    for (int j = 0; j < matchingPhotos.count; j++){


        PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
        requestOptions.resizeMode   = PHImageRequestOptionsResizeModeFast;
        requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat;
        requestOptions.synchronous = true;

        PHImageManager *manager = [PHImageManager defaultManager];
        [manager requestImageForAsset:matchingPhotos[j] targetSize:CGSizeMake(100, 100) contentMode:PHImageContentModeDefault options:requestOptions  resultHandler:^void(UIImage *image, NSDictionary *info) {
            @autoreleasepool {

                [finalArray addObject:image];

            }
        }];
    }
    return finalArray;
}

0 个答案:

没有答案