[MM-14899] Support sharing of screenshots via the iOS share extension (#2697)
* Handle NSItemProvider item of type UIImage * Create screenshot temp file with UploadSessionManager
This commit is contained in:
parent
64337b4851
commit
6fef6d6b92
1 changed files with 20 additions and 5 deletions
|
|
@ -19,6 +19,7 @@ class ShareViewController: SLComposeServiceViewController {
|
|||
private var serverURL: String?
|
||||
private var message: String?
|
||||
private var publicURL: String?
|
||||
private var tempContainerURL: URL? = UploadSessionManager.shared.tempContainerURL() as URL?
|
||||
|
||||
fileprivate var selectedChannel: Item?
|
||||
fileprivate var selectedTeam: Item?
|
||||
|
|
@ -195,6 +196,19 @@ class ShareViewController: SLComposeServiceViewController {
|
|||
attachment?.type = kUTTypeImage as String
|
||||
self.attachments.append(attachment!)
|
||||
}
|
||||
} else if let image = item as? UIImage {
|
||||
if let data = image.pngData() {
|
||||
let tempImageURL = self.tempContainerURL?
|
||||
.appendingPathComponent(UUID().uuidString)
|
||||
.appendingPathExtension(".png")
|
||||
if (try? data.write(to: tempImageURL!)) != nil {
|
||||
let attachment = self.saveAttachment(url: tempImageURL!)
|
||||
if (attachment != nil) {
|
||||
attachment?.type = kUTTypeImage as String
|
||||
self.attachments.append(attachment!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.dispatchGroup.leave()
|
||||
|
|
@ -339,16 +353,17 @@ class ShareViewController: SLComposeServiceViewController {
|
|||
}
|
||||
|
||||
func saveAttachment(url: URL) -> AttachmentItem? {
|
||||
let tempURL: URL? = UploadSessionManager.shared.tempContainerURL() as URL?
|
||||
let fileMgr = FileManager.default
|
||||
let fileName = url.lastPathComponent
|
||||
let tempFileURL = tempURL?.appendingPathComponent(fileName)
|
||||
let tempFileURL = tempContainerURL?.appendingPathComponent(fileName)
|
||||
|
||||
do {
|
||||
try? FileManager.default.removeItem(at: tempFileURL!)
|
||||
try fileMgr.copyItem(at: url, to: tempFileURL!)
|
||||
let attr = try fileMgr.attributesOfItem(atPath: (tempFileURL?.path)!) as NSDictionary
|
||||
if (tempFileURL != url) {
|
||||
try? FileManager.default.removeItem(at: tempFileURL!)
|
||||
try fileMgr.copyItem(at: url, to: tempFileURL!)
|
||||
}
|
||||
|
||||
let attr = try fileMgr.attributesOfItem(atPath: (tempFileURL?.path)!) as NSDictionary
|
||||
let attachment = AttachmentItem()
|
||||
attachment.fileName = fileName
|
||||
attachment.fileURL = tempFileURL
|
||||
|
|
|
|||
Loading…
Reference in a new issue