Updated GamePickerController for tvOS
This commit is contained in:
parent
7746ada490
commit
f77d16c9ce
@ -35,32 +35,49 @@ class GamePickerController: NSObject
|
||||
{
|
||||
self.presentingViewController = presentingViewController
|
||||
|
||||
let documentMenuController = UIDocumentMenuViewController(documentTypes: Array(Game.supportedTypeIdentifiers()), inMode: .Import)
|
||||
documentMenuController.delegate = self
|
||||
|
||||
documentMenuController.addOptionWithTitle(NSLocalizedString("iTunes", comment: ""), image: nil, order: .First, handler: self.importFromiTunes)
|
||||
|
||||
self.presentingViewController?.presentViewController(documentMenuController, animated: true, completion: nil)
|
||||
#if os(iOS)
|
||||
let documentMenuController = UIDocumentMenuViewController(documentTypes: Array(Game.supportedTypeIdentifiers()), inMode: .Import)
|
||||
documentMenuController.delegate = self
|
||||
documentMenuController.addOptionWithTitle(NSLocalizedString("iTunes", comment: ""), image: nil, order: .First) { self.importFromiTunes(nil) }
|
||||
self.presentingViewController?.presentViewController(documentMenuController, animated: true, completion: nil)
|
||||
#else
|
||||
self.importFromiTunes(completion)
|
||||
#endif
|
||||
}
|
||||
|
||||
private func importFromiTunes()
|
||||
private func importFromiTunes(completion: (Void -> Void)?)
|
||||
{
|
||||
let documentsDirectoryURL = NSFileManager.defaultManager().URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask).first
|
||||
let alertController = UIAlertController(title: NSLocalizedString("Import from iTunes?", comment: ""), message: NSLocalizedString("Delta will import the games copied over via iTunes.", comment: ""), preferredStyle: .Alert)
|
||||
|
||||
do
|
||||
{
|
||||
let contents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsDirectoryURL!, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
|
||||
let importAction = UIAlertAction(title: NSLocalizedString("Import", comment: ""), style: .Default) { action in
|
||||
|
||||
let gameURLs = contents.filter({ Game.typeIdentifierForURL($0) != nil })
|
||||
self.importGamesAtURLs(gameURLs)
|
||||
let documentsDirectoryURL = DatabaseManager.databaseDirectoryURL.URLByDeletingLastPathComponent
|
||||
|
||||
do
|
||||
{
|
||||
let contents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsDirectoryURL!, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
|
||||
|
||||
let gameURLs = contents.filter({ Game.typeIdentifierForURL($0) != nil })
|
||||
self.importGamesAtURLs(gameURLs)
|
||||
|
||||
}
|
||||
catch let error as NSError
|
||||
{
|
||||
print(error)
|
||||
}
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
|
||||
}
|
||||
catch let error as NSError
|
||||
{
|
||||
print(error)
|
||||
}
|
||||
alertController.addAction(importAction)
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .Cancel) { action in
|
||||
self.delegate?.gamePickerControllerDidCancel(self)
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
alertController.addAction(cancelAction)
|
||||
|
||||
self.presentingViewController?.presentViewController(alertController, animated: true, completion: completion)
|
||||
}
|
||||
|
||||
private func importGamesAtURLs(URLs: [NSURL])
|
||||
@ -81,47 +98,51 @@ class GamePickerController: NSObject
|
||||
}
|
||||
}
|
||||
|
||||
extension GamePickerController: UIDocumentMenuDelegate
|
||||
{
|
||||
func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController)
|
||||
#if os(iOS)
|
||||
|
||||
extension GamePickerController: UIDocumentMenuDelegate
|
||||
{
|
||||
documentPicker.delegate = self
|
||||
self.presentingViewController?.presentViewController(documentPicker, animated: true, completion: nil)
|
||||
func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController)
|
||||
{
|
||||
documentPicker.delegate = self
|
||||
self.presentingViewController?.presentViewController(documentPicker, animated: true, completion: nil)
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
|
||||
func documentMenuWasCancelled(documentMenu: UIDocumentMenuViewController)
|
||||
{
|
||||
self.delegate?.gamePickerControllerDidCancel(self)
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
|
||||
func documentMenuWasCancelled(documentMenu: UIDocumentMenuViewController)
|
||||
extension GamePickerController: UIDocumentPickerDelegate
|
||||
{
|
||||
self.delegate?.gamePickerControllerDidCancel(self)
|
||||
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL)
|
||||
{
|
||||
self.importGamesAtURLs([url])
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
func documentPickerWasCancelled(controller: UIDocumentPickerViewController)
|
||||
{
|
||||
self.delegate?.gamePickerControllerDidCancel(self)
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension GamePickerController: UIDocumentPickerDelegate
|
||||
{
|
||||
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL)
|
||||
{
|
||||
self.importGamesAtURLs([url])
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
|
||||
func documentPickerWasCancelled(controller: UIDocumentPickerViewController)
|
||||
{
|
||||
self.delegate?.gamePickerControllerDidCancel(self)
|
||||
|
||||
self.presentingViewController?.gamePickerController = nil
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private var GamePickerControllerKey: UInt8 = 0
|
||||
|
||||
extension UIViewController
|
||||
{
|
||||
var gamePickerController: GamePickerController?
|
||||
private(set) var gamePickerController: GamePickerController?
|
||||
{
|
||||
set
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user