[iOS开发]获取PHAsset 图片路径

https://stackoverflow.com/questions/28887638/how-to-get-an-alasset-url-from-a-phasset

NSArray *resources = [PHAssetResource assetResourcesForAsset:assets.lastObject];
        NSString *orgFilename = ((PHAssetResource*)resources[0]).originalFilename;
        NSLog(@"orgFilename:%@",orgFilename);
        assets.lastObject.localIdentifier  获取图片路径
        NSLog(@"---%@", assets.lastObject.localIdentifier);
//Here is working code tested on iOS 11 both simulator and device

PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
    [result enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        PHAsset *asset = (PHAsset *)obj;
        [asset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
            NSLog(@"URL:%@",  contentEditingInput.fullSizeImageURL.absoluteString);
            NSString* path = [contentEditingInput.fullSizeImageURL.absoluteString substringFromIndex:7];//screw all the crap of file://
            NSFileManager *fileManager = [NSFileManager defaultManager];
            BOOL isExist = [fileManager fileExistsAtPath:path];
            if (isExist)
                NSLog(@"oh yeah");
            else {
                NSLog(@"damn");
            }
        }];
    }];

你可能感兴趣的:([iOS开发]获取PHAsset 图片路径)