parent
2d8e2f0824
commit
a9a9bfebeb
|
@ -8,6 +8,8 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionActivationRule</key>
|
<key>NSExtensionActivationRule</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>NSExtensionActivationSupportsText</key>
|
||||||
|
<true/>
|
||||||
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
|
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
|
||||||
<integer>4</integer>
|
<integer>4</integer>
|
||||||
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
|
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
|
||||||
|
|
|
@ -71,36 +71,43 @@ class ShareViewController: UIViewController {
|
||||||
|
|
||||||
private func getDraftConfigurationFromExtensionContext() async -> (String, [DraftAttachment]) {
|
private func getDraftConfigurationFromExtensionContext() async -> (String, [DraftAttachment]) {
|
||||||
guard let extensionContext,
|
guard let extensionContext,
|
||||||
let inputItem = (extensionContext.inputItems as? [NSExtensionItem])?.first,
|
let inputItem = (extensionContext.inputItems as? [NSExtensionItem])?.first else {
|
||||||
let itemProvider = inputItem.attachments?.first else {
|
|
||||||
return ("", [])
|
return ("", [])
|
||||||
}
|
}
|
||||||
if let url: NSURL = await getObject(from: itemProvider) {
|
var text: String = ""
|
||||||
if let title = inputItem.attributedTitle ?? inputItem.attributedContentText {
|
var url: URL?
|
||||||
return ("\n\n\(title.string)\n\(url.absoluteString ?? "")", [])
|
var attachments: [DraftAttachment] = []
|
||||||
} else {
|
|
||||||
return ("\n\n\(url.absoluteString ?? "")", [])
|
for itemProvider in inputItem.attachments ?? [] {
|
||||||
}
|
if let attached: NSURL = await getObject(from: itemProvider) {
|
||||||
} else if let text: NSString = await getObject(from: itemProvider) {
|
if url == nil {
|
||||||
return ("\n\n\(text)", [])
|
url = attached as URL
|
||||||
} else if let attributedContent = inputItem.attributedContentText {
|
|
||||||
return ("\n\n\(attributedContent.string)", [])
|
|
||||||
} else {
|
|
||||||
let attachments = await withTaskGroup(of: DraftAttachment?.self, returning: [DraftAttachment].self) { group in
|
|
||||||
for provider in inputItem.attachments! {
|
|
||||||
group.addTask { @MainActor in
|
|
||||||
await self.getObject(from: provider)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if let s: NSString = await getObject(from: itemProvider) {
|
||||||
return await group.reduce(into: [], { partialResult, result in
|
if text.isEmpty {
|
||||||
if let result {
|
text = s as String
|
||||||
partialResult.append(result)
|
}
|
||||||
}
|
} else if let attachment: DraftAttachment = await getObject(from: itemProvider) {
|
||||||
})
|
attachments.append(attachment)
|
||||||
}
|
}
|
||||||
return ("", attachments)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if text.isEmpty,
|
||||||
|
let s = inputItem.attributedTitle ?? inputItem.attributedContentText {
|
||||||
|
text = s.string
|
||||||
|
}
|
||||||
|
|
||||||
|
if let url {
|
||||||
|
if !text.isEmpty {
|
||||||
|
text += "\n"
|
||||||
|
}
|
||||||
|
text += url.absoluteString
|
||||||
|
}
|
||||||
|
|
||||||
|
if !text.isEmpty {
|
||||||
|
text = "\n\n\(text)"
|
||||||
|
}
|
||||||
|
return (text, attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getObject<T: NSItemProviderReading>(from itemProvider: NSItemProvider) async -> T? {
|
private func getObject<T: NSItemProviderReading>(from itemProvider: NSItemProvider) async -> T? {
|
||||||
|
|
Loading…
Reference in New Issue