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