Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. //
  2. // ShareViewController.swift
  3. // Share
  4. //
  5. // Created by hoemoon on 19/04/2017.
  6. // Copyright © 2017 hoemoon. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Social
  11. import MobileCoreServices
  12.  
  13. class ShareViewController: SLComposeServiceViewController {
  14. private var urlString: String?
  15. private var userDecks = [Deck]()
  16. fileprivate var selectedDeck: Deck?
  17.  
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20.  
  21. for i in 1...3 {
  22. let deck = Deck()
  23. deck.title = "Deck \(i)"
  24. userDecks.append(deck)
  25. }
  26. selectedDeck = userDecks.first
  27.  
  28. let extensionItem = extensionContext?.inputItems.first as! NSExtensionItem
  29. let itemProvider = extensionItem.attachments?.first as! NSItemProvider
  30. let propertyList = String(kUTTypePropertyList)
  31. if itemProvider.hasItemConformingToTypeIdentifier(propertyList) {
  32. itemProvider.loadItem(forTypeIdentifier: propertyList, options: nil, completionHandler: { (item, error) -> Void in
  33. guard let dictionary = item as? NSDictionary else { return }
  34. OperationQueue.main.addOperation {
  35. if let results = dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary,
  36. let urlString = results["baseURI"] as? String {
  37. self.urlString = urlString
  38. print(urlString, "ee")
  39. }
  40. }
  41. })
  42. } else {
  43. print("error")
  44. }
  45.  
  46. let imageView = UIImageView(image: UIImage(named: "cat"))
  47. imageView.contentMode = .scaleAspectFit
  48. navigationItem.titleView = imageView
  49. navigationController?.navigationBar.topItem?.titleView = imageView
  50. navigationController?.navigationBar.tintColor = .white
  51. navigationController?.navigationBar.backgroundColor = UIColor(red: 0.39, green: 0.46, blue: 0.86, alpha: 1.00)
  52. }
  53.  
  54. override func isContentValid() -> Bool {
  55. return true
  56. }
  57.  
  58. override func didSelectPost() {
  59. print("hihi")
  60. let tagSelectVC = TagSelectViewController()
  61. self.present(tagSelectVC, animated: true, completion: nil)
  62. self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
  63. }
  64.  
  65. override func configurationItems() -> [Any]! {
  66. // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
  67. let item = SLComposeSheetConfigurationItem()
  68. item?.title = "Selected Deck"
  69. item?.value = selectedDeck?.title
  70. item?.tapHandler = {
  71. let vc = ShareSelectViewController()
  72. vc.userDecks = self.userDecks
  73. vc.delegate = self
  74. self.pushConfigurationViewController(vc)
  75. }
  76. return [item]
  77. }
  78. }
  79.  
  80.  
  81. extension ShareViewController: ShareSelectViewControllerDelegate {
  82. func selected(deck: Deck) {
  83. selectedDeck = deck
  84. reloadConfigurationItems()
  85. popConfigurationViewController()
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement