Fix share extension type priority

This commit is contained in:
Justin Mazzocchi 2021-02-24 15:39:48 -08:00
parent b735e08427
commit d2750ccc4d
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
1 changed files with 15 additions and 13 deletions

View File

@ -148,28 +148,30 @@ public extension CompositionViewModel {
parentViewModel: NewStatusViewModel) { parentViewModel: NewStatusViewModel) {
self.init(eventsSubject: eventsSubject) self.init(eventsSubject: eventsSubject)
guard let inputItem = extensionContext.inputItems.first as? NSExtensionItem, guard let inputItem = extensionContext.inputItems.first as? NSExtensionItem else { return }
let itemProvider = inputItem.attachments?.first
else { return }
if itemProvider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) { if let urlItemProvider = inputItem.attachments?.first(where: {
itemProvider.loadItem(forTypeIdentifier: UTType.plainText.identifier, options: nil) { result, _ in $0.hasItemConformingToTypeIdentifier(UTType.url.identifier)
guard let text = result as? String else { return } }) {
urlItemProvider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { result, _ in
self.text = text
}
} else if itemProvider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
itemProvider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { result, _ in
guard let url = result as? URL else { return } guard let url = result as? URL else { return }
if let contentText = inputItem.attributedContentText?.string { if let contentText = inputItem.attributedContentText?.string, !contentText.isEmpty {
self.text.append(contentText) self.text.append(contentText)
self.text.append("\n\n") self.text.append("\n\n")
} }
self.text.append(url.absoluteString) self.text.append(url.absoluteString)
} }
} else { } else if let plainTextItemProvider = inputItem.attachments?.first(where: {
$0.hasItemConformingToTypeIdentifier(UTType.plainText.identifier)
}) {
plainTextItemProvider.loadItem(forTypeIdentifier: UTType.plainText.identifier, options: nil) { result, _ in
guard let text = result as? String else { return }
self.text = text
}
} else if let itemProvider = inputItem.attachments?.first {
attach(itemProvider: itemProvider, parentViewModel: parentViewModel) attach(itemProvider: itemProvider, parentViewModel: parentViewModel)
} }
} }