Updated GamePickerController for tvOS
This commit is contained in:
parent
7746ada490
commit
f77d16c9ce
@ -35,32 +35,49 @@ class GamePickerController: NSObject
|
|||||||
{
|
{
|
||||||
self.presentingViewController = presentingViewController
|
self.presentingViewController = presentingViewController
|
||||||
|
|
||||||
let documentMenuController = UIDocumentMenuViewController(documentTypes: Array(Game.supportedTypeIdentifiers()), inMode: .Import)
|
#if os(iOS)
|
||||||
documentMenuController.delegate = self
|
let documentMenuController = UIDocumentMenuViewController(documentTypes: Array(Game.supportedTypeIdentifiers()), inMode: .Import)
|
||||||
|
documentMenuController.delegate = self
|
||||||
documentMenuController.addOptionWithTitle(NSLocalizedString("iTunes", comment: ""), image: nil, order: .First, handler: self.importFromiTunes)
|
documentMenuController.addOptionWithTitle(NSLocalizedString("iTunes", comment: ""), image: nil, order: .First) { self.importFromiTunes(nil) }
|
||||||
|
self.presentingViewController?.presentViewController(documentMenuController, animated: true, completion: 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 importAction = UIAlertAction(title: NSLocalizedString("Import", comment: ""), style: .Default) { action in
|
||||||
{
|
|
||||||
let contents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsDirectoryURL!, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
|
|
||||||
|
|
||||||
let gameURLs = contents.filter({ Game.typeIdentifierForURL($0) != nil })
|
let documentsDirectoryURL = DatabaseManager.databaseDirectoryURL.URLByDeletingLastPathComponent
|
||||||
self.importGamesAtURLs(gameURLs)
|
|
||||||
|
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
|
alertController.addAction(importAction)
|
||||||
{
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
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])
|
private func importGamesAtURLs(URLs: [NSURL])
|
||||||
@ -81,47 +98,51 @@ class GamePickerController: NSObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension GamePickerController: UIDocumentMenuDelegate
|
#if os(iOS)
|
||||||
{
|
|
||||||
func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController)
|
extension GamePickerController: UIDocumentMenuDelegate
|
||||||
{
|
{
|
||||||
documentPicker.delegate = self
|
func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController)
|
||||||
self.presentingViewController?.presentViewController(documentPicker, animated: true, completion: nil)
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
#endif
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var GamePickerControllerKey: UInt8 = 0
|
private var GamePickerControllerKey: UInt8 = 0
|
||||||
|
|
||||||
extension UIViewController
|
extension UIViewController
|
||||||
{
|
{
|
||||||
var gamePickerController: GamePickerController?
|
private(set) var gamePickerController: GamePickerController?
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user