保存された写真アルバムから特定の条件に一致するすべての画像の配列を作成しようとしています。ここでは簡単なコードを示します。 myImages配列に写真を追加し、 "Added Image"ログで正しい画像が記録されることを確認します。しかし、関数が返す配列は常に空です。 Objective-Cにはかなり新しいので、どんな提案も参考になるはずです。保存された写真の配列は常に空に戻されます
NSMutableArray * myImages = [NSMutableArray array];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullResolutionImage]];
NSLog(@"Added Image");
[myImages addObject:latestPhoto];
}
}];
}
failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];
return myImages;
はい、imagesTakenOnDateはmyImagesである必要があります。私はあなたの提案を読んで、それを試みます。ありがとう! – vishwa