Once my share extension is loaded, not everytime and not everything is visible for user immediately. The most common is that there you can see image, number of images, and content text. However there are cases where there is a lot more informations.
I know that within SLComposeServiceViewController there is extensionContext and its inputItems property.
Ok, so I stopped the debugger at time, and print out on console some things with following command:
po (extensionContext!.inputItems[0] as! NSExtensionItem).userInfo![NSExtensionItemAttachmentsKey]
there was two NSItemProvider objects as attachments to first NSExtensionItem

Ok, then I print out the first of attachments:

NSItemProvider and url from the next one? Can you deliver some code?I suppose we will use
loadItemForTypeIdentifier(_:options:completionHandler:)
but do not know how.
import MobileCoreServices
There is a simple function you can apply to your code:
private func fetchAndSetContentFromContext() {
    guard let extensionItems = extensionContext?.inputItems as? [NSExtensionItem] else {
        return
    }
    for extensionItem in extensionItems {
        if let itemProviders = extensionItem.attachments as? [NSItemProvider] {
            for itemProvider in itemProviders {
                if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeText as String) {
                    itemProvider.loadItemForTypeIdentifier(kUTTypeText as String, options: nil, completionHandler: { text, error in
                    })
                }
            }
        }
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With