2022-11-11 16:57:37 +05:30
|
|
|
import Social
|
|
|
|
import UIKit
|
2022-12-04 17:51:50 +05:30
|
|
|
import UniformTypeIdentifiers
|
2022-11-11 16:57:37 +05:30
|
|
|
|
|
|
|
final class ShareViewController: SLComposeServiceViewController {
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
2022-11-26 00:12:50 +05:30
|
|
|
openExtensionContextURLs()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func openExtensionContextURLs() {
|
|
|
|
for item in extensionContext?.inputItems as! [NSExtensionItem] {
|
2022-11-11 16:57:37 +05:30
|
|
|
if let attachments = item.attachments {
|
2022-11-26 00:12:50 +05:30
|
|
|
tryToOpenItemForUrlTypeIdentifier(attachments)
|
2022-12-04 17:51:50 +05:30
|
|
|
tryToOpenItemForPlainTextTypeIdentifier(attachments)
|
2022-11-26 00:12:50 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func tryToOpenItemForPlainTextTypeIdentifier(_ attachments: [NSItemProvider]) {
|
2022-12-04 17:51:50 +05:30
|
|
|
for itemProvider in attachments {
|
|
|
|
itemProvider.loadItem(forTypeIdentifier: UTType.plainText.identifier, options: nil) { item, _ in
|
2022-11-26 00:12:50 +05:30
|
|
|
if let url = (item as? String),
|
|
|
|
let absoluteURL = URL(string: url)?.absoluteURL
|
|
|
|
{
|
|
|
|
if let url = URL(string: "yattee://\(absoluteURL.absoluteString)") {
|
|
|
|
self.open(url: url)
|
2022-11-11 16:57:37 +05:30
|
|
|
}
|
2022-11-26 00:12:50 +05:30
|
|
|
|
2022-12-04 17:51:50 +05:30
|
|
|
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
|
|
|
}
|
2022-11-26 00:12:50 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func tryToOpenItemForUrlTypeIdentifier(_ attachments: [NSItemProvider]) {
|
2022-12-04 17:51:50 +05:30
|
|
|
for itemProvider in attachments {
|
|
|
|
itemProvider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { item, _ in
|
2022-11-26 00:12:50 +05:30
|
|
|
if let url = (item as? NSURL), let absoluteURL = url.absoluteURL {
|
|
|
|
if let url = URL(string: "yattee://\(absoluteURL.absoluteString)") {
|
|
|
|
self.open(url: url)
|
|
|
|
}
|
|
|
|
|
2023-05-19 15:32:47 +05:30
|
|
|
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
2022-12-04 17:51:50 +05:30
|
|
|
}
|
2022-11-11 16:57:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func open(url: URL) {
|
|
|
|
var responder: UIResponder? = self as UIResponder
|
|
|
|
let selector = #selector(openURL(_:))
|
|
|
|
|
|
|
|
while responder != nil {
|
|
|
|
if responder!.responds(to: selector), responder != self {
|
|
|
|
responder!.perform(selector, with: url)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
responder = responder?.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc
|
|
|
|
private func openURL(_: URL) {}
|
|
|
|
|
|
|
|
override func isContentValid() -> Bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
override func didSelectPost() {
|
2022-11-26 00:12:50 +05:30
|
|
|
openExtensionContextURLs()
|
2022-11-11 16:57:37 +05:30
|
|
|
extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func configurationItems() -> [Any]! {
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
}
|