0

我需要获取照片库中最新图像的文件路径。我怎样才能做到这一点?

4

2 回答 2

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);
}];
于 2013-09-10T02:33:52.040 回答
0

没有办法只访问最近的照片。

于 2013-09-12T06:40:27.003 回答