diff --git a/ios/ImagePickerManager.mm b/ios/ImagePickerManager.mm index 6ba5c7383..93e99bee4 100644 --- a/ios/ImagePickerManager.mm +++ b/ios/ImagePickerManager.mm @@ -4,8 +4,7 @@ #import #import #import - -@import MobileCoreServices; +#import @interface ImagePickerManager () @@ -67,12 +66,12 @@ @implementation ImagePickerManager - (void)launchImagePicker:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback { self.callback = callback; - + if (target == camera && [ImagePickerUtils isSimulator]) { self.callback(@[@{@"errorCode": errCameraUnavailable}]); return; } - + self.options = options; #if __has_include() @@ -85,7 +84,7 @@ - (void)launchImagePicker:(NSDictionary *)options callback:(RCTResponseSenderBlo picker.presentationController.delegate = self; if([self.options[@"includeExtra"] boolValue]) { - + [self checkPhotosPermissions:^(BOOL granted) { if (!granted) { self.callback(@[@{@"errorCode": errPermission}]); @@ -96,7 +95,7 @@ - (void)launchImagePicker:(NSDictionary *)options callback:(RCTResponseSenderBlo } else { [self showPickerViewController:picker]; } - + return; } } @@ -132,7 +131,7 @@ - (void) showPickerViewController:(UIViewController *)picker NSData* extractImageData(UIImage* image){ CFMutableDataRef imageData = CFDataCreateMutable(NULL, 0); CGImageDestinationRef destination = CGImageDestinationCreateWithData(imageData, kUTTypeJPEG, 1, NULL); - + CFStringRef orientationKey[1]; CFTypeRef orientationValue[1]; CGImagePropertyOrientation CGOrientation = CGImagePropertyOrientationForUIImageOrientation(image.imageOrientation); @@ -142,11 +141,11 @@ - (void) showPickerViewController:(UIViewController *)picker CFDictionaryRef imageProps = CFDictionaryCreate( NULL, (const void **)orientationKey, (const void **)orientationValue, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - + CGImageDestinationAddImage(destination, image.CGImage, imageProps); - + CGImageDestinationFinalize(destination); - + CFRelease(destination); CFRelease(orientationValue[0]); CFRelease(imageProps); @@ -163,7 +162,7 @@ -(NSMutableDictionary *)mapImageToAsset:(UIImage *)image data:(NSData *)data phA } data = extractImageData(image); } - + UIImage* newImage = image; if (![fileType isEqualToString:@"gif"]) { newImage = [ImagePickerUtils resizeImage:image @@ -179,7 +178,7 @@ -(NSMutableDictionary *)mapImageToAsset:(UIImage *)image data:(NSData *)data phA data = UIImagePNGRepresentation(newImage); } } - + NSMutableDictionary *asset = [[NSMutableDictionary alloc] init]; asset[@"type"] = [@"image/" stringByAppendingString:fileType]; @@ -204,13 +203,13 @@ -(NSMutableDictionary *)mapImageToAsset:(UIImage *)image data:(NSData *)data phA asset[@"fileName"] = fileName; asset[@"width"] = @(newImage.size.width); asset[@"height"] = @(newImage.size.height); - + if(phAsset){ asset[@"timestamp"] = [self getDateTimeInUTC:phAsset.creationDate]; asset[@"id"] = phAsset.localIdentifier; // Add more extra data here ... } - + return asset; } @@ -237,10 +236,10 @@ -(NSMutableDictionary *)mapVideoToAsset:(NSURL *)url phAsset:(PHAsset * _Nullabl if ((target == camera) && [self.options[@"saveToPhotos"] boolValue]) { UISaveVideoAtPathToSavedPhotosAlbum(url.path, nil, nil, nil); } - + if (![url.URLByResolvingSymlinksInPath.path isEqualToString:videoDestinationURL.URLByResolvingSymlinksInPath.path]) { NSFileManager *fileManager = [NSFileManager defaultManager]; - + // Delete file if it already exists if ([fileManager fileExistsAtPath:videoDestinationURL.path]) { [fileManager removeItemAtURL:videoDestinationURL error:nil]; @@ -260,25 +259,25 @@ -(NSMutableDictionary *)mapVideoToAsset:(NSURL *)url phAsset:(PHAsset * _Nullabl } } } - + NSMutableDictionary *response = [[NSMutableDictionary alloc] init]; - + if([self.options[@"formatAsMp4"] boolValue] && ![fileExtension isEqualToString:@"mp4"]) { NSURL *parentURL = [videoDestinationURL URLByDeletingLastPathComponent]; NSString *path = [[parentURL.path stringByAppendingString:@"/"] stringByAppendingString:[[NSUUID UUID] UUIDString]]; path = [path stringByAppendingString:@".mp4"]; NSURL *outputURL = [NSURL fileURLWithPath:path]; - + [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoDestinationURL options:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough]; - + exportSession.outputURL = outputURL; exportSession.outputFileType = AVFileTypeMPEG4; exportSession.shouldOptimizeForNetworkUse = YES; - + dispatch_semaphore_t sem = dispatch_semaphore_create(0); - + [exportSession exportAsynchronouslyWithCompletionHandler:^(void) { if (exportSession.status == AVAssetExportSessionStatusCompleted) { CGSize dimentions = [ImagePickerUtils getVideoDimensionsFromUrl:outputURL]; @@ -289,14 +288,14 @@ -(NSMutableDictionary *)mapVideoToAsset:(NSURL *)url phAsset:(PHAsset * _Nullabl response[@"fileSize"] = [ImagePickerUtils getFileSizeFromUrl:outputURL]; response[@"width"] = @(dimentions.width); response[@"height"] = @(dimentions.height); - + dispatch_semaphore_signal(sem); } else if (exportSession.status == AVAssetExportSessionStatusFailed || exportSession.status == AVAssetExportSessionStatusCancelled) { dispatch_semaphore_signal(sem); } }]; - + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); } else { CGSize dimentions = [ImagePickerUtils getVideoDimensionsFromUrl:videoDestinationURL]; @@ -307,7 +306,7 @@ -(NSMutableDictionary *)mapVideoToAsset:(NSURL *)url phAsset:(PHAsset * _Nullabl response[@"fileSize"] = [ImagePickerUtils getFileSizeFromUrl:videoDestinationURL]; response[@"width"] = @(dimentions.width); response[@"height"] = @(dimentions.height); - + if(phAsset){ response[@"timestamp"] = [self getDateTimeInUTC:phAsset.creationDate]; response[@"id"] = phAsset.localIdentifier; @@ -457,12 +456,12 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking if ([info[UIImagePickerControllerMediaType] isEqualToString:(NSString *) kUTTypeImage]) { UIImage *image = [ImagePickerManager getUIImageFromInfo:info]; - + [assets addObject:[self mapImageToAsset:image data:[NSData dataWithContentsOfURL:[ImagePickerManager getNSURLFromInfo:info]] phAsset:asset]]; } else { NSError *error; NSDictionary *videoAsset = [self mapVideoToAsset:info[UIImagePickerControllerMediaURL] phAsset:asset error:&error]; - + if (videoAsset == nil) { NSString *errorMessage = error.localizedFailureReason; if (errorMessage == nil) errorMessage = @"Video asset not found"; @@ -513,7 +512,7 @@ - (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray "https://github.com/react-native-image-picker/react-native-image-picker.git", :tag => "v#{s.version}" } s.source_files = "ios/*.{h,m,mm}" - s.pod_target_xcconfig = { 'OTHER_CPLUSPLUSFLAGS' => '-fcxx-modules' } - if ENV['RCT_NEW_ARCH_ENABLED'] == '1' - folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' + s.frameworks = "MobileCoreServices" - s.pod_target_xcconfig = { - 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"', - 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17' - } - - s.compiler_flags = folly_compiler_flags + ' -DRN_FABRIC_ENABLED -fmodules -fcxx-modules' - - s.dependency "React" - s.dependency "React-RCTFabric" # This is for fabric component - s.dependency "React-Codegen" - s.dependency "RCT-Folly" - s.dependency "RCTRequired" - s.dependency "RCTTypeSafety" - s.dependency "ReactCommon/turbomodule/core" + if defined?(install_modules_dependencies) != nil + install_modules_dependencies(s) else - s.dependency "React-Core" + + if ENV['RCT_NEW_ARCH_ENABLED'] == '1' + folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' + + s.pod_target_xcconfig = { + 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"', + 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17' + } + + s.compiler_flags = folly_compiler_flags + ' -DRN_FABRIC_ENABLED -fmodules -fcxx-modules' + + s.dependency "React" + s.dependency "React-RCTFabric" # This is for fabric component + s.dependency "React-Codegen" + s.dependency "RCT-Folly" + s.dependency "RCTRequired" + s.dependency "RCTTypeSafety" + s.dependency "ReactCommon/turbomodule/core" + else + s.dependency "React-Core" + end end end