4

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

Ro4ch
  • 850
  • 8
  • 21
  • @salman Ghumsani, I do not want to download the image I just want the URL the share extension uses. In the link you provided I am not seeing how he retrieved the url. – Ro4ch Sep 24 '17 at 09:01
  • I'm not sure this is achievable. I believe the NSItemProvider's `previewImageHandler` can return either a URL or a Data object, and those are used internally to present a thumbnail, but aren't technically part of the shared payload, and therefore wouldn't be available to a share extension. – Palpatim Sep 26 '17 at 14:15
  • i think you can convert url into string and then can split string at / and further you can split each index with . by using perhaps you will be able to get the extensions used in url. – Abu Ul Hassan Oct 02 '17 at 06:56
  • Please note that in your completion handler the first parameter is of type NSSecureCoding. Not in all cases a URL is coerced but it could also be Data or even in some rare cases an UIImage-object. see my post/question here: https://stackoverflow.com/questions/47219339/ios-swift-share-extension-what-are-all-and-the-best-ways-to-handle-images – Hilmar Demant Nov 10 '17 at 12:28

1 Answers1

0

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

Albi
  • 1,705
  • 1
  • 17
  • 28