diff --git a/FlowCrypt/Functionality/PhotosManager/PhotosManager.swift b/FlowCrypt/Functionality/PhotosManager/PhotosManager.swift index e9c73c6ad..2df622db4 100644 --- a/FlowCrypt/Functionality/PhotosManager/PhotosManager.swift +++ b/FlowCrypt/Functionality/PhotosManager/PhotosManager.swift @@ -20,6 +20,12 @@ enum PhotosManagerError: Error { } class PhotosManager: PhotosManagerType { + + enum MediaType { + static let image = "public.image" + static let video = "public.movie" + } + func selectPhoto( source: UIImagePickerController.SourceType, from viewController: UIViewController & UIImagePickerControllerDelegate & UINavigationControllerDelegate @@ -29,18 +35,9 @@ class PhotosManager: PhotosManagerType { let imagePicker = UIImagePickerController() imagePicker.delegate = viewController imagePicker.sourceType = source - PHPhotoLibrary.requestAuthorization { status in - switch status { - case .authorized: - DispatchQueue.main.async { - viewController.present(imagePicker, animated: true, completion: nil) - } - promise(.success(())) - case .denied, .restricted, .notDetermined, .limited: - promise(.failure(PhotosManagerError.noAccessToLibrary)) - @unknown default: fatalError() - } - } + imagePicker.mediaTypes = [MediaType.image, MediaType.video] + viewController.present(imagePicker, animated: true, completion: nil) + promise(.success(())) } } } diff --git a/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageAttachment.swift b/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageAttachment.swift index 13b4409e3..6f8e7074d 100644 --- a/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageAttachment.swift +++ b/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageAttachment.swift @@ -18,21 +18,30 @@ struct ComposeMessageAttachment { extension ComposeMessageAttachment { init?(librarySourceMediaInfo: [UIImagePickerController.InfoKey: Any]) { - guard let image = librarySourceMediaInfo[.originalImage] as? UIImage, - let data = image.jpegData(compressionQuality: 1), - let asset = librarySourceMediaInfo[.phAsset] as? PHAsset else { - return nil + guard let mediaType = librarySourceMediaInfo[.mediaType] as? String else { + return nil } - let assetResources = PHAssetResource.assetResources(for: asset) - guard let fileName = assetResources.first?.originalFilename else { - return nil + let urlKey: UIImagePickerController.InfoKey + switch mediaType { + case PhotosManager.MediaType.image: + urlKey = .imageURL + case PhotosManager.MediaType.video: + urlKey = .mediaURL + default: return nil } - self.name = "\(fileName).pgp" - self.data = data - self.size = data.count - self.type = fileName.mimeType + do { + guard let url = librarySourceMediaInfo[urlKey] as? URL else { return nil } + let data = try Data(contentsOf: url) + + self.name = "\(url.lastPathComponent).pgp" + self.data = data + self.size = data.count + self.type = url.lastPathComponent.mimeType + } catch { + return nil + } } init?(cameraSourceMediaInfo: [UIImagePickerController.InfoKey: Any]) { diff --git a/FlowCrypt/Info.plist b/FlowCrypt/Info.plist index cff7e16a9..04af2ee37 100644 --- a/FlowCrypt/Info.plist +++ b/FlowCrypt/Info.plist @@ -75,7 +75,5 @@ UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortraitUpsideDown - UIViewControllerBasedStatusBarAppearance -