Uses UIAlertController instead of UIDocumentMenuViewController for Cydia Impactor builds

This commit is contained in:
Riley Testut 2017-05-09 20:40:32 -07:00
parent f81830230f
commit e5f232b7b2
4 changed files with 53 additions and 24 deletions

View File

@ -1029,6 +1029,7 @@
INFOPLIST_FILE = "Delta/Supporting Files/Info.plist"; INFOPLIST_FILE = "Delta/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0; IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" -DIMPACTOR";
PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Delta/Supporting Files/Delta-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Delta/Supporting Files/Delta-Bridging-Header.h";

View File

@ -7,11 +7,12 @@
// //
import UIKit import UIKit
import MobileCoreServices
import ObjectiveC import ObjectiveC
import DeltaCore import DeltaCore
import MobileCoreServices import Roxas
protocol ImportControllerDelegate protocol ImportControllerDelegate
{ {
@ -49,6 +50,23 @@ class ImportController: NSObject
{ {
self.presentingViewController = presentingViewController 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) let documentMenuController = UIDocumentMenuViewController(documentTypes: Array(self.documentTypes), in: .import)
documentMenuController.delegate = self documentMenuController.delegate = self
@ -56,22 +74,27 @@ class ImportController: NSObject
{ {
for importOption in reversedImportOptions for importOption in reversedImportOptions
{ {
documentMenuController.add(importOption, order: UIDocumentMenuOrder.first) { (urls) in documentMenuController.add(importOption, order: .first, completionHandler: finish(with:))
if let urls = urls
{
self.delegate?.importController(self, didImportItemsAt: urls)
}
else
{
self.delegate?.importControllerDidCancel(self)
}
self.presentingViewController?.importController = nil
}
} }
} }
self.presentingViewController?.present(documentMenuController, animated: true, completion: nil) self.presentingViewController?.present(documentMenuController, animated: true, completion: nil)
#endif
}
fileprivate func finish(with urls: Set<URL>?)
{
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) func documentMenuWasCancelled(_ documentMenu: UIDocumentMenuViewController)
{ {
self.delegate?.importControllerDidCancel(self) self.finish(with: nil)
self.presentingViewController?.importController = nil
} }
} }
@ -96,16 +117,12 @@ extension ImportController: UIDocumentPickerDelegate
{ {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL)
{ {
self.delegate?.importController(self, didImportItemsAt: [url]) self.finish(with: [url])
self.presentingViewController?.importController = nil
} }
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController)
{ {
self.delegate?.importControllerDidCancel(self) self.finish(with: nil)
self.presentingViewController?.importController = nil
} }
} }

View File

@ -20,6 +20,17 @@ extension UIDocumentMenuViewController
} }
} }
extension UIAlertController
{
func add(_ importOption: ImportOption, completionHandler: @escaping (Set<URL>?) -> Void)
{
let action = UIAlertAction(title: importOption.title, style: .default, handler: { action in
importOption.import(withCompletionHandler: completionHandler)
})
self.addAction(action)
}
}
protocol ImportOption protocol ImportOption
{ {
var title: String { get } var title: String { get }

2
External/Roxas vendored

@ -1 +1 @@
Subproject commit 9143d01afa25f07da8f1cdb5390b49f4efb1a75f Subproject commit 356ea5d714ee48ddf4a976b89a9579bb7d05b938