Skip to content

Commit

Permalink
[IOS] FIX: Return original filename instead of FullSizeRender (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
xick authored Oct 2, 2023
1 parent bc58292 commit e096d5e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ that can be found in the LICENSE file. -->
### Fixes

- Correct the key when fetching video info with MMR on Android. (#997)
- Retrieve original media instead of one with adjustments/filters for subtype files on iOS. (#976)
- Returns original file name instead of `FullSizeRender.*` if this has adjustments on iOS. (#976)

### Improvements

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;
- (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

0 comments on commit e096d5e

Please sign in to comment.