Fix sharing extension only using first attachment

This commit is contained in:
Shadowfacts 2023-04-22 22:43:00 -04:00
parent de1a97d357
commit a12afb8dc2
1 changed files with 14 additions and 3 deletions

View File

@ -84,12 +84,23 @@ class ShareViewController: UIViewController {
}
} else if let text: NSString = await getObject(from: itemProvider) {
return ("\n\n\(text)", [])
} else if let attachment: DraftAttachment = await getObject(from: itemProvider) {
return ("", [attachment])
} else if let attributedContent = inputItem.attributedContentText {
return ("\n\n\(attributedContent.string)", [])
} else {
return ("", [])
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)
}
}
return await group.reduce(into: [], { partialResult, result in
if let result {
partialResult.append(result)
}
})
}
return ("", attachments)
}
}