Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions FlowCrypt/Functionality/PhotosManager/PhotosManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
2 changes: 0 additions & 2 deletions FlowCrypt/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,5 @@
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
</plist>