Skip to content

Instantly share code, notes, and snippets.

@scottfister
Created April 17, 2017 17:10
Show Gist options
  • Save scottfister/4aa021d002e3106b2d36fc2e63f12bb6 to your computer and use it in GitHub Desktop.
Save scottfister/4aa021d002e3106b2d36fc2e63f12bb6 to your computer and use it in GitHub Desktop.
let extensionItem = extensionContext?.inputItems.first as! NSExtensionItem
let itemProvider = extensionItem.attachments?.first as! NSItemProvider
let propertyList = String(kUTTypePropertyList)
if itemProvider.hasItemConformingToTypeIdentifier(propertyList) {
itemProvider.loadItem(forTypeIdentifier: propertyList, options: nil, completionHandler: { (item, error) -> Void in
guard let dictionary = item as? NSDictionary else { return }
OperationQueue.main.addOperation {
if let results = dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary,
let urlString = results["URL"] as? String,
let url = NSURL(string: urlString) {
print("URL retrieved: \(urlString)")
}
}
})
} else {
print("error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment