简体   繁体   中英

ios swift extension show error

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)

}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM