Retrieving imageURL from Share Extension

Viewed 563

I am trying to get the imageURL the ios share extension uses for the thumbnail generated in the action sheet.

I am retrieving the URL fine but cannot seem to figure out how to get the imageURL.

Here is how I get the normal URL,

 if let item = extensionContext?.inputItems.first as? NSExtensionItem {
        if let itemProvider = item.attachments?.first as? NSItemProvider {      
            if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeItem as String) {
                itemProvider.loadItem(forTypeIdentifier: kUTTypeItem as String, options: nil, completionHandler: { (url, error) -> Void in
                    if let shareURL = url as? NSURL {

                        let components = URLComponents(url:shareURL as URL, resolvingAgainstBaseURL: true)
                        if  let host = components?.host { self.shareTitle = host }
                        self.shareURL = shareURL.absoluteString!                            
                        self.POSTShareData(completion: nil)
                    }
                    self.extensionContext?.completeRequest(returningItems: [], completionHandler:nil)
                })
            }
        }
    }

I have tried to changing the typeIdentifier to kUTTypeImage to no avail. I have my info.plist set to NSExtensionActivationRule to TRUEPREDICATE to see what I can retrieve. I am thinking maybe I have to be more explicit in the .plist ??

I am targeting iOS 9.3

1 Answers

A workaround is that you can store that URL link in common UserDefaults

eg:- let defaults = UserDefaults(suiteName: "group.com.common.Notification")

Then access it in-app or extension

Related