diff --git a/packages/app/ios/RNFBApp/RNFBUtilsModule.m b/packages/app/ios/RNFBApp/RNFBUtilsModule.m index bccf3aeaa5..f43b9b67d0 100644 --- a/packages/app/ios/RNFBApp/RNFBUtilsModule.m +++ b/packages/app/ios/RNFBApp/RNFBUtilsModule.m @@ -15,7 +15,6 @@ * */ -#import #import #import "RNFBApp/RNFBSharedUtils.h" @@ -39,56 +38,54 @@ + (BOOL)requiresMainQueueSetup { #pragma mark Firebase Utils Methods + (BOOL)isRemoteAsset:(NSString *)localFilePath { - return [localFilePath hasPrefix:@"assets-library://"] || - [localFilePath hasPrefix:@"ph://"]; + return [localFilePath hasPrefix:@"assets-library://"] || [localFilePath hasPrefix:@"ph://"]; } + (BOOL)unused_isHeic:(NSString *)localFilePath { - return [[localFilePath pathExtension] caseInsensitiveCompare:@"heic"] == - NSOrderedSame; + return [[localFilePath pathExtension] caseInsensitiveCompare:@"heic"] == NSOrderedSame; } + (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", key]; - NSURLQueryItem *queryItem = - [[queryItems filteredArrayUsingPredicate:predicate] firstObject]; + NSURLQueryItem *queryItem = [[queryItems filteredArrayUsingPredicate:predicate] firstObject]; return queryItem.value; } + (PHAsset *)fetchAssetForPath:(NSString *)localFilePath { PHAsset *asset; - if ([localFilePath hasPrefix:@"assets-library://"]) { - NSURL *localFile = [[NSURL alloc] initWithString:localFilePath]; - asset = [[PHAsset fetchAssetsWithALAssetURLs:@[ localFile ] - options:nil] firstObject]; + if ([localFilePath hasPrefix:@"assets-library://"] || [localFilePath hasPrefix:@"ph://"]) { + if ([localFilePath hasPrefix:@"assets-library://"]) { + NSURL *localFile = [[NSURL alloc] initWithString:localFilePath]; + asset = [[PHAsset fetchAssetsWithALAssetURLs:@[localFile] options:nil] firstObject]; + } else { + NSString *assetId = [localFilePath substringFromIndex:@"ph://".length]; + asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil] firstObject]; + } } else { - NSURLComponents *components = - [NSURLComponents componentsWithString:localFilePath]; + NSURLComponents *components = [NSURLComponents componentsWithString:localFilePath]; NSArray *queryItems = components.queryItems; NSString *assetId = [self valueForKey:@"id" fromQueryItems:queryItems]; - asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[ assetId ] - options:nil] firstObject]; + asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil] firstObject]; } return asset; } - (NSString *)getPathForDirectory:(int)directory { - NSArray *paths = NSSearchPathForDirectoriesInDomains( - (NSSearchPathDirectory)directory, NSUserDomainMask, YES); + NSArray *paths = NSSearchPathForDirectoriesInDomains((NSSearchPathDirectory) directory, NSUserDomainMask, YES); return [paths firstObject]; } - (NSDictionary *)constantsToExport { NSMutableDictionary *constants = [@{ - @"MAIN_BUNDLE" : [[NSBundle mainBundle] bundlePath], - @"CACHES_DIRECTORY" : [self getPathForDirectory:NSCachesDirectory], - @"DOCUMENT_DIRECTORY" : [self getPathForDirectory:NSDocumentDirectory], - @"PICTURES_DIRECTORY" : [self getPathForDirectory:NSPicturesDirectory], - @"MOVIES_DIRECTORY" : [self getPathForDirectory:NSMoviesDirectory], - @"TEMP_DIRECTORY" : NSTemporaryDirectory(), - @"LIBRARY_DIRECTORY" : [self getPathForDirectory:NSLibraryDirectory], + @"MAIN_BUNDLE": [[NSBundle mainBundle] bundlePath], + @"CACHES_DIRECTORY": [self getPathForDirectory:NSCachesDirectory], + @"DOCUMENT_DIRECTORY": [self getPathForDirectory:NSDocumentDirectory], + @"PICTURES_DIRECTORY": [self getPathForDirectory:NSPicturesDirectory], + @"MOVIES_DIRECTORY": [self getPathForDirectory:NSMoviesDirectory], + @"TEMP_DIRECTORY": NSTemporaryDirectory(), + @"LIBRARY_DIRECTORY": [self getPathForDirectory:NSLibraryDirectory], } mutableCopy]; return constants;