Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOS] FIX: Return original filename instead of FullSizeRender #990

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ that can be found in the LICENSE file. -->

# CHANGELOG

## 2.7.3
xick marked this conversation as resolved.
Show resolved Hide resolved

### Fixes

- [iOS] Add PHAsset extension method `getUntouchedResource` to retrieve original media instead of one with adjustments / filters.
- [iOS] Fix: When retrieving an asset title, now returns original file name instead of `FullSizeRender.*` if this has adjustments. (#976)
xick marked this conversation as resolved.
Show resolved Hide resolved

## 2.7.2

### Fixes
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/core/PHAsset+PM_COMMON.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSString*)mimeType;
- (BOOL)isAdjust;
- (PHAssetResource *)getAdjustResource;
- (PHAssetResource *)getUntouchedResource;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to affect the file of Live Photos. What's the difference between them? Any specs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAdjustResource return by default media with adjustments ( PHAssetResourceTypeFullSizePhoto/Video) if there are any.
getUntouchedResource will always return original asset (PHAssetResourceTypePhoto/*Video).
LivePhotos are not affected by this, because there are already dedicated methods to deal with them. For example, when retrieving filename of an asset, will check if media type is LivePhoto and use the dedicated method:

- (NSString *)originalFilenameWithSubtype:(int)subtype {
    if (@available(iOS 9.1, *)) {
        if ([self isLivePhoto] && subtype == PHAssetMediaSubtypePhotoLive) {
            return [self getLivePhotosResource].originalFilename;
        }
    }
    PHAssetResource *resource = [self getUntouchedResource];
    if (resource) {
        return resource.originalFilename;
    }

getLivePhotosResource currently will always returns original video asset ( PHAssetResourceTypePairedVideo), and there are no method to retrieve the asset with adjustments, hence we could add this possibility.

- (void)requestAdjustedData:(void (^)(NSData *_Nullable result))block;
- (PHAssetResource *)getLivePhotosResource;

Expand Down
27 changes: 26 additions & 1 deletion ios/Classes/core/PHAsset+PM_COMMON.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (NSString *)originalFilenameWithSubtype:(int)subtype {
return [self getLivePhotosResource].originalFilename;
}
}
PHAssetResource *resource = [self getAdjustResource];
PHAssetResource *resource = [self getUntouchedResource];
if (resource) {
return resource.originalFilename;
}
Expand Down Expand Up @@ -120,6 +120,31 @@ - (BOOL)videoIsAdjust:(NSArray<PHAssetResource *> *)resources {
return NO;
}

- (PHAssetResource *)getUntouchedResource {
NSArray<PHAssetResource *> *resources = [PHAssetResource assetResourcesForAsset:self];
if (resources.count == 0) {
return nil;
}

if (resources.count == 1) {
return resources[0];
}

for (PHAssetResource *res in resources) {
if (self.mediaType == PHAssetMediaTypeImage
&& res.type == PHAssetResourceTypePhoto) {
return res;
}

if (self.mediaType == PHAssetMediaTypeVideo
&& res.type == PHAssetResourceTypeVideo) {
return res;
}
}

return nil;
}

- (PHAssetResource *)getAdjustResource {
NSArray<PHAssetResource *> *resources = [PHAssetResource assetResourcesForAsset:self];
if (resources.count == 0) {
Expand Down