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



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

您可以使用素材资源库访问用户的照片。

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);
}];

无法只访问最新的照片。