   }
   
   
-  func urlRequestWithExtensionItem(extensionItem: NSExtensionItem, text: String) -> NSURLRequest? {
-    let url = NSURL.URLWithString("http://requestb.in/oha28noh")
+  func urlRequestWithImage(image: UIImage?, text: String) -> NSURLRequest? {
+    let url = NSURL.URLWithString(sc_uploadURL)
     let request = NSMutableURLRequest(URL: url)
     request.addValue("application/json", forHTTPHeaderField: "Content-Type")
     request.addValue("application/json", forHTTPHeaderField: "Accept")

    
    var jsonObject = NSMutableDictionary()
    jsonObject["text"] = text
    jsonObject["image"] = pictureDetailsFromExtensionItem(extensionItem)
    
    
    let jsonData = NSJSONSerialization.dataWithJSONObject(jsonObject, options: nil, error: nil)
    request.HTTPBody = jsonData
    
    return request
  }
  
  func pictureDetailsFromExtensionItem(extensionItem: NSExtensionItem) -> [String:String] {
    
    for attachment in extensionItem.attachments as [NSItemProvider] {
      if(attachment.hasItemConformingToTypeIdentifier(kUTTypeImage)) {
        attachment.loadItemForTypeIdentifier(kUTTypeImage, options: nil,
          completionHandler: {
            (image: NSSecureCoding!, error: NSError!) in
            let castedImage = image as UIImage
            println(castedImage)
          })
      }
    }
    return ["picture": "hi"]
  }
  
}


class ShareViewController: SLComposeServiceViewController {
  
  // The URL we're uploading to.
  // NOTE: This almost certainly _won't_ work for you. Create your own request bin
  //       at http://requestb.in/ and substitute that URL here.
  let sc_uploadURL = "http://requestb.in/oha28noh"
  var attachedImage: UIImage?
  
  
  override func isContentValid() -> Bool {
    // Do validation of contentText and/or NSExtensionContext attachments here
    return true
  }
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    // Only interested in the first item
    let extensionItem = extensionContext.inputItems[0] as NSExtensionItem
    // Extract an image (if one exists)
    imageFromExtensionItem(extensionItem) {
      image in
      if image {
        self.attachedImage = image
      }
    }
  }
  
  override func didSelectPost() {
    // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
    let configName = "com.shinobicontrols.ShareAlike.BackgroundSessionConfig"
    let sessionConfig = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(configName)
    // Extensions aren't allowed their own cache disk space. Need to share with application
    sessionConfig.sharedContainerIdentifier = "group.ShareAlike"
    let session = NSURLSession(configuration: sessionConfig)
    
    // Prepare the URL Request
    let request = urlRequestWithImage(attachedImage, text: "hello")
    
    // Create the task, and kick it off
    let task = session.dataTaskWithRequest(request)
