fix(storage,ios): Fix issue with ph:// (Photos) paths

This commit is contained in:
Salakar
2019-10-24 16:17:38 +01:00
parent 5d60639197
commit cbced419d4

View File

@@ -15,7 +15,6 @@
*
*/
#import <Firebase/Firebase.h>
#import <React/RCTUtils.h>
#import "RNFBApp/RNFBSharedUtils.h"
@@ -39,56 +38,54 @@ RCT_EXPORT_MODULE();
#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;