Created
April 16, 2018 15:21
-
-
Save mlcollard/5c0fafa7c001131fbf928437ce4d1c92 to your computer and use it in GitHub Desktop.
iOS: didSelectPost() processing for share extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func didSelectPost() { | |
// content of the post | |
print(#function, #line, self.contentText ?? "NO CONTENT") | |
// extract URL from attachments | |
if let item = extensionContext?.inputItems.first as? NSExtensionItem, | |
let itemProvider = item.attachments?.first as? NSItemProvider, | |
itemProvider.hasItemConformingToTypeIdentifier("public.url") { | |
itemProvider.loadItem(forTypeIdentifier: "public.url", options: nil) { | |
url, error in | |
if let error = error { | |
print(#function, #line, error) | |
return | |
} | |
if let shareURL = url as? NSURL { | |
print(shareURL) | |
} | |
self.extensionContext?.completeRequest(returningItems: [], completionHandler:nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment