我正试图从iphone相机胶卷中获取最后一张照片。我使用以下代码:
UIImage* __block image = [[UIImage alloc] init];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup* group, BOOL* stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
if ([group numberOfAssets] > 0) {
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:[group numberOfAssets]-1] options:NSEnumerationConcurrent usingBlock:^(ALAsset* alAsset, NSUInteger index, BOOL* innerStop) {
if (alAsset) {
ALAssetRepresentation* rawImage = [alAsset defaultRepresentation];
image = [UIImage imageWithCGImage:[rawImage fullScreenImage]];
[self doTheJobWithImage:image];
// Inside doTheJobWithImage: a segue is also performed at the end
}
}];
}
} failureBlock:^(NSError* error) {
NSLog(@"Error: %@", [error localizedDescription]);
}];
它有效但有缺陷(我正在使用Instruments和Zombies来调试它):
我正在使用xcode 4.6,ios 6和ARC。提前谢谢。
答案 0 :(得分:1)
几个小时后,我发现这里的代码没有任何问题。这是在相机胶卷中提取最后一张照片的正确代码(如果有人需要的话)。问题出在doTheJobWithImage里面:我解决了它取代
[self doTheJobWithImage:image];
并将生成的图像存储在其他地方,然后执行doTheJobWithImage:图片枚举完成后...说这是为了以防其他人感兴趣。