如何获取照片库中最新照片的路径? (作为NSUrl或字符串)

时间:2013-09-10 00:28:49

标签: ios alassetslibrary

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

2 个答案:

答案 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)

无法访问最新的照片。