Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ShareViewController.swift
- // Share
- //
- // Created by hoemoon on 19/04/2017.
- // Copyright © 2017 hoemoon. All rights reserved.
- //
- import UIKit
- import Social
- import MobileCoreServices
- class ShareViewController: SLComposeServiceViewController {
- private var urlString: String?
- private var userDecks = [Deck]()
- fileprivate var selectedDeck: Deck?
- override func viewDidLoad() {
- super.viewDidLoad()
- for i in 1...3 {
- let deck = Deck()
- deck.title = "Deck \(i)"
- userDecks.append(deck)
- }
- selectedDeck = userDecks.first
- let extensionItem = extensionContext?.inputItems.first as! NSExtensionItem
- let itemProvider = extensionItem.attachments?.first as! NSItemProvider
- let propertyList = String(kUTTypePropertyList)
- if itemProvider.hasItemConformingToTypeIdentifier(propertyList) {
- itemProvider.loadItem(forTypeIdentifier: propertyList, options: nil, completionHandler: { (item, error) -> Void in
- guard let dictionary = item as? NSDictionary else { return }
- OperationQueue.main.addOperation {
- if let results = dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary,
- let urlString = results["baseURI"] as? String {
- self.urlString = urlString
- print(urlString, "ee")
- }
- }
- })
- } else {
- print("error")
- }
- let imageView = UIImageView(image: UIImage(named: "cat"))
- imageView.contentMode = .scaleAspectFit
- navigationItem.titleView = imageView
- navigationController?.navigationBar.topItem?.titleView = imageView
- navigationController?.navigationBar.tintColor = .white
- navigationController?.navigationBar.backgroundColor = UIColor(red: 0.39, green: 0.46, blue: 0.86, alpha: 1.00)
- }
- override func isContentValid() -> Bool {
- return true
- }
- override func didSelectPost() {
- print("hihi")
- let tagSelectVC = TagSelectViewController()
- self.present(tagSelectVC, animated: true, completion: nil)
- self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
- }
- override func configurationItems() -> [Any]! {
- // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
- let item = SLComposeSheetConfigurationItem()
- item?.title = "Selected Deck"
- item?.value = selectedDeck?.title
- item?.tapHandler = {
- let vc = ShareSelectViewController()
- vc.userDecks = self.userDecks
- vc.delegate = self
- self.pushConfigurationViewController(vc)
- }
- return [item]
- }
- }
- extension ShareViewController: ShareSelectViewControllerDelegate {
- func selected(deck: Deck) {
- selectedDeck = deck
- reloadConfigurationItems()
- popConfigurationViewController()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement