From 366734c889d9d46ae8c3db4588de49f902a0af7d Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 5 Aug 2020 14:56:00 +0100 Subject: [PATCH 1/2] fix(Storage): AL lib deprecated iOS 8 > --- packages/app/ios/RNFBApp/RNFBUtilsModule.m | 14 +++++++------- .../storage/ios/RNFBStorage/RNFBStorageCommon.m | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/app/ios/RNFBApp/RNFBUtilsModule.m b/packages/app/ios/RNFBApp/RNFBUtilsModule.m index 6feb422d84..c3068aa9c7 100644 --- a/packages/app/ios/RNFBApp/RNFBUtilsModule.m +++ b/packages/app/ios/RNFBApp/RNFBUtilsModule.m @@ -57,16 +57,16 @@ + (PHAsset *)fetchAssetForPath:(NSString *)localFilePath { if ([localFilePath hasPrefix:@"assets-library://"] || [localFilePath hasPrefix:@"ph://"]) { if ([localFilePath hasPrefix:@"assets-library://"]) { NSURL *localFile = [[NSURL alloc] initWithString:localFilePath]; -#if TARGET_OS_MACCATALYST - static BOOL hasWarned = NO; - if (!hasWarned) { + if (@available(macOS 11, *) || @available(iOS 12, *)) { + static BOOL hasWarned = NO; + if (!hasWarned) { NSLog(@"assets-library:// URLs are not supported in Catalyst-based targets; returning nil (future warnings will be suppressed)"); hasWarned = YES; + } + asset = nil; + } else { + asset = [[PHAsset fetchAssetsWithALAssetURLs:@[localFile] options:nil] firstObject]; } - asset = nil; -#else - asset = [[PHAsset fetchAssetsWithALAssetURLs:@[localFile] options:nil] firstObject]; -#endif } else { NSString *assetId = [localFilePath substringFromIndex:@"ph://".length]; asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil] firstObject]; diff --git a/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m b/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m index d54ee14f82..eb40abb8a7 100644 --- a/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m +++ b/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m @@ -79,6 +79,12 @@ + (void)NSURLForLocalFilePath:(NSString *)localFilePath completion:(void (^)( ))completion { if ([RNFBUtilsModule isRemoteAsset:localFilePath]) { PHAsset *asset = [RNFBUtilsModule fetchAssetForPath:localFilePath]; + + if (!asset) { + completion(@[@"asset-library-removed", @"iOS asset-library methodology has been removed, please provide the correct path to resource."], nil, nil); + + return; + } NSURL *temporaryFileUrl = [RNFBStorageCommon createTempFileUrl]; [RNFBStorageCommon downloadAsset:asset toURL:temporaryFileUrl completion:^( NSArray *errorCodeMessageArray, From 1e612fac42d394fcb80dbda79f820ac96261b585 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 5 Aug 2020 15:00:31 +0100 Subject: [PATCH 2/2] chore(Storage, iOS): imporve warning message --- packages/app/ios/RNFBApp/RNFBUtilsModule.m | 2 +- packages/storage/ios/RNFBStorage/RNFBStorageCommon.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app/ios/RNFBApp/RNFBUtilsModule.m b/packages/app/ios/RNFBApp/RNFBUtilsModule.m index c3068aa9c7..d3d4403b6f 100644 --- a/packages/app/ios/RNFBApp/RNFBUtilsModule.m +++ b/packages/app/ios/RNFBApp/RNFBUtilsModule.m @@ -60,7 +60,7 @@ + (PHAsset *)fetchAssetForPath:(NSString *)localFilePath { if (@available(macOS 11, *) || @available(iOS 12, *)) { static BOOL hasWarned = NO; if (!hasWarned) { - NSLog(@"assets-library:// URLs are not supported in Catalyst-based targets; returning nil (future warnings will be suppressed)"); + NSLog(@"'assets-library://' & 'ph://' URLs are not supported in Catalyst-based targets or iOS 12 and higher; returning nil (future warnings will be suppressed)"); hasWarned = YES; } asset = nil; diff --git a/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m b/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m index eb40abb8a7..c94e5f54e2 100644 --- a/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m +++ b/packages/storage/ios/RNFBStorage/RNFBStorageCommon.m @@ -81,7 +81,7 @@ + (void)NSURLForLocalFilePath:(NSString *)localFilePath completion:(void (^)( PHAsset *asset = [RNFBUtilsModule fetchAssetForPath:localFilePath]; if (!asset) { - completion(@[@"asset-library-removed", @"iOS asset-library methodology has been removed, please provide the correct path to resource."], nil, nil); + completion(@[@"asset-library-removed", @"iOS 'asset-library://' & 'ph://' URLs have been removed, please provide the correct path to resource."], nil, nil); return; }