From 5d0c59e86398292ff555468a56ce87e1c5d33a79 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 15 Jun 2020 18:15:00 -0400 Subject: [PATCH] Prompt for Photos access before showing asset picker --- .../ComposeAttachmentsViewController.swift | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift b/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift index aef273d7..36efecad 100644 --- a/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift +++ b/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift @@ -10,6 +10,7 @@ import UIKit import Pachyderm import MobileCoreServices import PencilKit +import Photos protocol ComposeAttachmentsViewControllerDelegate: class { func composeSelectedAttachmentsDidChange() @@ -353,18 +354,23 @@ class ComposeAttachmentsViewController: UITableViewController { // MARK: Interaction func addAttachmentPressed() { - if traitCollection.horizontalSizeClass == .compact { - let sheetContainer = AssetPickerSheetContainerViewController() - sheetContainer.assetPicker.assetPickerDelegate = self - present(sheetContainer, animated: true) - } else { - let picker = AssetPickerViewController() - picker.assetPickerDelegate = self - picker.overrideUserInterfaceStyle = .dark - picker.modalPresentationStyle = .popover - present(picker, animated: true) - if let presentationController = picker.presentationController as? UIPopoverPresentationController { - presentationController.sourceView = tableView.cellForRow(at: IndexPath(row: 0, section: 1)) + PHPhotoLibrary.requestAuthorization { (status) in + guard status == .authorized else { return } + DispatchQueue.main.async { + if self.traitCollection.horizontalSizeClass == .compact { + let sheetContainer = AssetPickerSheetContainerViewController() + sheetContainer.assetPicker.assetPickerDelegate = self + self.present(sheetContainer, animated: true) + } else { + let picker = AssetPickerViewController() + picker.assetPickerDelegate = self + picker.overrideUserInterfaceStyle = .dark + picker.modalPresentationStyle = .popover + self.present(picker, animated: true) + if let presentationController = picker.presentationController as? UIPopoverPresentationController { + presentationController.sourceView = self.tableView.cellForRow(at: IndexPath(row: 0, section: 1)) + } + } } } }