我需要获取照片库中最新图像的文件路径。我怎么能这样做?
答案 0 :(得分:0)
您可以使用AssetsLibrary访问用户的照片。
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:group.numberOfAssets - 1] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
ALAssetRepresentation *rep;
rep = [result defaultRepresentation];
UIImage *image;
image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
//Now you can write this UIImage to a file path in your app's directory for future use
*stop = YES;
}
}];
}
*stop = NO;
} failureBlock:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
答案 1 :(得分:0)
无法访问最新的照片。