0

I've written an extension to share images to my web-service. The server is receiving the items without problem but something is happening on the server that execution is terminated before the expected state change.

I am trying to figure out how I can display a response from the web-server (like an error) after the post button has been hit in the share extension.

Is this possible? How can it be done?

my didSelectPost:

override func didSelectPost() {   
    let identifier = NSBundle.mainBundle().bundleIdentifier! + "." + NSUUID().UUIDString
    let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(identifier)

    configuration.sharedContainerIdentifier = "group.aa.com"

    let session = NSURLSession(configuration: configuration)

    let request = urlRequestWithImage(attachedImage, text: contentText)!

    let task = NSURLSession.sharedSession().dataTaskWithRequest(request)

    task.resume()

    extensionContext?.completeRequestReturningItems([], completionHandler: nil)

}
Jason G
  • 2,395
  • 2
  • 24
  • 34
  • Typically you would use delegates to handl all of the responses from the server. Also, in your code you set completionHandler to nil.. you might try adding error handling there. – Jordan Jan 15 '15 at 21:23
  • thanks for the reply, how would I go about doing this? – Jason G Jan 16 '15 at 14:05
  • Check this out for some examples: http://stackoverflow.com/questions/24040893/how-to-use-nsurlsessiondatatask-in-swift – Jordan Jan 16 '15 at 14:24

1 Answers1

0

In Xcode select the app running which is right between the STOP icon and the device selector. From there, choose the extension and run that in the simulator or on your attached device, now you will see the prints from your code in Xcode

shim
  • 9,289
  • 12
  • 69
  • 108
Jason G
  • 2,395
  • 2
  • 24
  • 34