mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
Fix opening URLs via share sheet
This commit is contained in:
parent
e8515d63e3
commit
779bf190f4
@ -5,8 +5,38 @@ final class ShareViewController: SLComposeServiceViewController {
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
for item in extensionContext!.inputItems as! [NSExtensionItem] {
|
||||
openExtensionContextURLs()
|
||||
|
||||
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
|
||||
private func openExtensionContextURLs() {
|
||||
for item in extensionContext?.inputItems as! [NSExtensionItem] {
|
||||
if let attachments = item.attachments {
|
||||
tryToOpenItemForPlainTextTypeIdentifier(attachments)
|
||||
tryToOpenItemForUrlTypeIdentifier(attachments)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func tryToOpenItemForPlainTextTypeIdentifier(_ attachments: [NSItemProvider]) {
|
||||
for itemProvider in attachments where itemProvider.hasItemConformingToTypeIdentifier("public.plain-text") {
|
||||
itemProvider.loadItem(forTypeIdentifier: "public.plain-text", options: nil) { item, _ in
|
||||
if let url = (item as? String),
|
||||
let absoluteURL = URL(string: url)?.absoluteURL
|
||||
{
|
||||
URLBookmarkModel.shared.saveBookmark(absoluteURL)
|
||||
if let url = URL(string: "yattee://\(absoluteURL.absoluteString)") {
|
||||
self.open(url: url)
|
||||
}
|
||||
}
|
||||
|
||||
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func tryToOpenItemForUrlTypeIdentifier(_ attachments: [NSItemProvider]) {
|
||||
for itemProvider in attachments where itemProvider.hasItemConformingToTypeIdentifier("public.url") {
|
||||
itemProvider.loadItem(forTypeIdentifier: "public.url", options: nil) { item, _ in
|
||||
if let url = (item as? NSURL), let absoluteURL = url.absoluteURL {
|
||||
@ -15,12 +45,11 @@ final class ShareViewController: SLComposeServiceViewController {
|
||||
self.open(url: url)
|
||||
}
|
||||
}
|
||||
|
||||
self.extensionContext!.completeRequest(returningItems: nil, completionHandler: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func open(url: URL) {
|
||||
var responder: UIResponder? = self as UIResponder
|
||||
@ -45,6 +74,7 @@ final class ShareViewController: SLComposeServiceViewController {
|
||||
}
|
||||
|
||||
override func didSelectPost() {
|
||||
openExtensionContextURLs()
|
||||
extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user