title: Presenting UIViewController from SKScene?
body: <p>So at the beginning I was having trouble implementing social media sharing into my project using Swift/Sprite-Kit. I believe I have now accomplished that but I just cannot trigger the methods, or as it seems everybody's struggle, I cannot present the view controller from my SKScene. So what I first did, was to create my buttons on my EndGame Scene. Then on my touchesEnded method I called the NSNotificationCenter. Something like this: </p>
  
  <pre><code>import SpriteKit
  import UIKit
  import Social
  
  class EndGameScene: SKScene {
  
  var facebookButton: SKNode! = nil
  var twitterButton: SKNode! = nil
  
  
  required init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
  }
  
  override init(size: CGSize) {
      super.init(size: size)
  
      // FacebookButton
      facebookButton = SKSpriteNode(imageNamed: "facebookButton")
      facebookButton.position = CGPoint(x: self.size.width * 0.3 , y: self.size.height * 0.45);
      addChild(facebookButton)
  
      // TwitterButton
      twitterButton = SKSpriteNode(imageNamed: "twitterButton")
      twitterButton.position = CGPoint(x: self.size.width * 0.5 , y: self.size.height * 0.45);
      addChild(twitterButton)
  
  
  }
  
  override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
  
      for touch: AnyObject in touches {
  
          let location = touch.locationInNode(self)
  
          if facebookButton.containsPoint(location) {
             NSLog("Button tapped")
             NSNotificationCenter.defaultCenter().postNotificationName("FacebookID", object: nil)
  
          }
  
          if twitterButton.containsPoint(location) {
              NSLog("Button tapped")
              NSNotificationCenter.defaultCenter().postNotificationName("TwitterID", object: nil)
  
          }
  
  
      }
  
  }
  </code></pre>
  
  <p>Then I created my SocialViewController with the methods that are supposed to be triggered with help of the NSNotificationCenter to show the sheets. This is the code I used for it:</p>
  
  <pre><code>import UIKit
  import Social
  
  class SocialViewController: UIViewController {
  
  override func viewDidLoad() {
      super.viewDidLoad()
      NSNotificationCenter.defaultCenter().addObserver(self, selector: "showTweetSheet", name: "TwitterID", object: nil)
      NSNotificationCenter.defaultCenter().addObserver(self, selector: "showFacebookSheet", name: "FacebookID", object: nil)
  }
  
  func showTweetSheet() {
      let tweetSheet = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
      tweetSheet.completionHandler = {
          result in
          switch result {
          case SLComposeViewControllerResult.Cancelled:
              break
          case SLComposeViewControllerResult.Done:
              break
          }
      }
  
      tweetSheet.setInitialText("Test Twitter")
      tweetSheet.addImage(UIImage(named: "TestImage.png"))
      tweetSheet.addURL(NSURL(string: "http://twitter.com"))
      self.presentViewController(tweetSheet, animated: false, completion: {
      })
  }
  
  func showFacebookSheet() {
      let facebookSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
      facebookSheet.completionHandler = {
          result in
          switch result {
          case SLComposeViewControllerResult.Cancelled:
              break
          case SLComposeViewControllerResult.Done:
              break
          }
      }
      facebookSheet.setInitialText("Test Facebook")
      facebookSheet.addImage(UIImage(named: "TestImage.png")) 
      facebookSheet.addURL(NSURL(string: "http://facebook.com")) 
      self.presentViewController(facebookSheet, animated: false, completion: {
      })
  }
  </code></pre>
  
  <p>I literally have no idea on what I might be missing or doing wrong. I've read several posts on this and using the NSNotificationCenter is supposed to be the best way to accomplish this but seems is not working for me. So if there is anyone there that could help me out I would really appreciate it. Thanks in advance! </p>