Prompt for Photos access before showing asset picker

This commit is contained in:
Shadowfacts 2020-06-15 18:15:00 -04:00
parent c7b4d00da7
commit 5d0c59e863
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 18 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import UIKit
import Pachyderm import Pachyderm
import MobileCoreServices import MobileCoreServices
import PencilKit import PencilKit
import Photos
protocol ComposeAttachmentsViewControllerDelegate: class { protocol ComposeAttachmentsViewControllerDelegate: class {
func composeSelectedAttachmentsDidChange() func composeSelectedAttachmentsDidChange()
@ -353,18 +354,23 @@ class ComposeAttachmentsViewController: UITableViewController {
// MARK: Interaction // MARK: Interaction
func addAttachmentPressed() { func addAttachmentPressed() {
if traitCollection.horizontalSizeClass == .compact { PHPhotoLibrary.requestAuthorization { (status) in
guard status == .authorized else { return }
DispatchQueue.main.async {
if self.traitCollection.horizontalSizeClass == .compact {
let sheetContainer = AssetPickerSheetContainerViewController() let sheetContainer = AssetPickerSheetContainerViewController()
sheetContainer.assetPicker.assetPickerDelegate = self sheetContainer.assetPicker.assetPickerDelegate = self
present(sheetContainer, animated: true) self.present(sheetContainer, animated: true)
} else { } else {
let picker = AssetPickerViewController() let picker = AssetPickerViewController()
picker.assetPickerDelegate = self picker.assetPickerDelegate = self
picker.overrideUserInterfaceStyle = .dark picker.overrideUserInterfaceStyle = .dark
picker.modalPresentationStyle = .popover picker.modalPresentationStyle = .popover
present(picker, animated: true) self.present(picker, animated: true)
if let presentationController = picker.presentationController as? UIPopoverPresentationController { if let presentationController = picker.presentationController as? UIPopoverPresentationController {
presentationController.sourceView = tableView.cellForRow(at: IndexPath(row: 0, section: 1)) presentationController.sourceView = self.tableView.cellForRow(at: IndexPath(row: 0, section: 1))
}
}
} }
} }
} }