Skip to content

Commit

Permalink
[IOS] Add method to retrieve untouched resource
Browse files Browse the repository at this point in the history
(IN TESTING) Add method to retrieve original photo/video instead of altered one. getTitleAsync now returns original filename instead of 'FullsizeRender'.
  • Loading branch information
xick committed Sep 17, 2023
1 parent 5cbb6c6 commit 122b1db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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 122b1db

Please sign in to comment.