Commit f888a4f5 authored by Martin's avatar Martin
Browse files

IOS-2437 - address comments from review

parent a40da595
......@@ -480,28 +480,19 @@ extension ComposeViewController {
extension ComposeViewController {
private func presentMediaAttachmentPickerProvider() {
if #available(iOS 14.0, *) {
var configuration = PHPickerConfiguration()
configuration.filter = .any(of: [.livePhotos, .images, .videos])
configuration.preferredAssetRepresentationMode = .current
let picker = PHPickerViewController(configuration: configuration)
picker.delegate = mediaAttachmentPickerProvider
present(picker, animated: true)
} else {
let media = Capability.media
media.requestAndInformUserInErrorCase(viewController: self) {
[weak self] (permissionsGranted: Bool, error: Capability.AccessError?) in
guard permissionsGranted else {
return
}
guard let me = self,
let picker = me.mediaAttachmentPickerProvider?.imagePicker else {
// Valid case. We might have been dismissed already.
return
}
me.present(picker, animated: true)
mediaAttachmentPickerProvider?.getPicker(from: self, { [weak self] picker in
guard let me = self else {
Log.shared.errorAndCrash("Lost myself")
return nil
}
}
guard let picker = picker else {
// Valid case: lack of permissions for example.
// Nothing to do.
return nil
}
me.present(picker, animated: true)
return nil
})
}
}
......
......@@ -27,6 +27,36 @@ class MediaAttachmentPickerProvider: NSObject {
super.init()
setup()
}
/// Retrieve the picker if possible, otherwise nil.
/// It could be nil due lack of permissions.
/// - Parameters:
/// - requesterViewController: The VC that request the picker will be used to show alert to inform the user in case no permission is granted for iOS versions less than 14.
/// - callback: The callback with the picker.
func getPicker(from requesterViewController: UIViewController, _ callback: @escaping (UIViewController?) -> ()?) {
if #available(iOS 14.0, *) {
var configuration = PHPickerConfiguration()
configuration.filter = .any(of: [.livePhotos, .images, .videos])
configuration.preferredAssetRepresentationMode = .current
let picker = PHPickerViewController(configuration: configuration)
picker.delegate = self
callback(picker)
} else {
let media = Capability.media
media.requestAndInformUserInErrorCase(viewController: requesterViewController)
{ [weak self] (permissionsGranted: Bool, error: Capability.AccessError?) in
guard permissionsGranted else {
callback(nil)
return
}
guard let me = self else {
Log.shared.errorAndCrash("Lost myself")
return
}
callback(me.imagePicker)
}
}
}
}
// MARK: - UIImagePickerControllerDelegate
......
......@@ -98,7 +98,7 @@ extension MediaAttachmentPickerProviderViewModel {
extension MediaAttachmentPickerProviderViewModel {
//MARK: - iOS version greater than iOS14
// iOS version greater than iOS14
private func createMovieAttchmentAndInformResultDelegate(url: URL) {
createAttachment(forResource: url, session: session) {[weak self] (attachment) in
......@@ -150,7 +150,7 @@ extension MediaAttachmentPickerProviderViewModel {
}
}
//MARK: - iOS version lower than iOS14
// iOS version lower than iOS14
private func createImageAttchmentAndInformResultDelegate(info: [UIImagePickerController.InfoKey: Any]) {
guard
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment