diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index 6eddb56..aa89185 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -1029,6 +1029,7 @@ INFOPLIST_FILE = "Delta/Supporting Files/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" -DIMPACTOR"; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Delta/Supporting Files/Delta-Bridging-Header.h"; diff --git a/Delta/Importing/ImportController.swift b/Delta/Importing/ImportController.swift index 065ae7d..8de44e4 100644 --- a/Delta/Importing/ImportController.swift +++ b/Delta/Importing/ImportController.swift @@ -7,11 +7,12 @@ // import UIKit +import MobileCoreServices import ObjectiveC import DeltaCore -import MobileCoreServices +import Roxas protocol ImportControllerDelegate { @@ -49,6 +50,23 @@ class ImportController: NSObject { self.presentingViewController = presentingViewController +#if IMPACTOR + + let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) + alertController.addAction(UIAlertAction.cancel) + + if let importOptions = self.importOptions + { + for importOption in importOptions + { + alertController.add(importOption, completionHandler: finish(with:)) + } + } + + self.presentingViewController?.present(alertController, animated: true, completion: nil) + +#else + let documentMenuController = UIDocumentMenuViewController(documentTypes: Array(self.documentTypes), in: .import) documentMenuController.delegate = self @@ -56,22 +74,27 @@ class ImportController: NSObject { for importOption in reversedImportOptions { - documentMenuController.add(importOption, order: UIDocumentMenuOrder.first) { (urls) in - if let urls = urls - { - self.delegate?.importController(self, didImportItemsAt: urls) - } - else - { - self.delegate?.importControllerDidCancel(self) - } - - self.presentingViewController?.importController = nil - } + documentMenuController.add(importOption, order: .first, completionHandler: finish(with:)) } } - + self.presentingViewController?.present(documentMenuController, animated: true, completion: nil) +#endif + + } + + fileprivate func finish(with urls: Set?) + { + if let urls = urls + { + self.delegate?.importController(self, didImportItemsAt: urls) + } + else + { + self.delegate?.importControllerDidCancel(self) + } + + self.presentingViewController?.importController = nil } } @@ -86,9 +109,7 @@ extension ImportController: UIDocumentMenuDelegate func documentMenuWasCancelled(_ documentMenu: UIDocumentMenuViewController) { - self.delegate?.importControllerDidCancel(self) - - self.presentingViewController?.importController = nil + self.finish(with: nil) } } @@ -96,16 +117,12 @@ extension ImportController: UIDocumentPickerDelegate { func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { - self.delegate?.importController(self, didImportItemsAt: [url]) - - self.presentingViewController?.importController = nil + self.finish(with: [url]) } func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { - self.delegate?.importControllerDidCancel(self) - - self.presentingViewController?.importController = nil + self.finish(with: nil) } } diff --git a/Delta/Importing/ImportOption.swift b/Delta/Importing/ImportOption.swift index dfa7b9c..0f6dfda 100644 --- a/Delta/Importing/ImportOption.swift +++ b/Delta/Importing/ImportOption.swift @@ -20,6 +20,17 @@ extension UIDocumentMenuViewController } } +extension UIAlertController +{ + func add(_ importOption: ImportOption, completionHandler: @escaping (Set?) -> Void) + { + let action = UIAlertAction(title: importOption.title, style: .default, handler: { action in + importOption.import(withCompletionHandler: completionHandler) + }) + self.addAction(action) + } +} + protocol ImportOption { var title: String { get } diff --git a/External/Roxas b/External/Roxas index 9143d01..356ea5d 160000 --- a/External/Roxas +++ b/External/Roxas @@ -1 +1 @@ -Subproject commit 9143d01afa25f07da8f1cdb5390b49f4efb1a75f +Subproject commit 356ea5d714ee48ddf4a976b89a9579bb7d05b938