mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Fix saving images
This commit is contained in:
parent
f7ff1b8284
commit
99678e43fb
1 changed files with 34 additions and 21 deletions
|
@ -193,9 +193,15 @@ extension ImageViewController {
|
|||
}
|
||||
|
||||
func presentActivityViewController() {
|
||||
if let image = imageView.image {
|
||||
if let imageData = imageView.image?.sd_imageData(), let url = imageURL ?? viewModel?.attachment.url.url {
|
||||
let tempURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||
.appendingPathComponent(url.lastPathComponent)
|
||||
|
||||
do {
|
||||
try imageData.write(to: tempURL)
|
||||
|
||||
let activityViewController = UIActivityViewController(
|
||||
activityItems: [NSItemProvider(object: image)],
|
||||
activityItems: [tempURL],
|
||||
applicationActivities: [])
|
||||
|
||||
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||
|
@ -204,6 +210,9 @@ extension ImageViewController {
|
|||
}
|
||||
|
||||
present(activityViewController, animated: true)
|
||||
} catch {
|
||||
alertUnableToExportMedia()
|
||||
}
|
||||
} else if let asset = playerView.player?.currentItem?.asset as? AVURLAsset {
|
||||
asset.exportWithoutAudioTrack { result in
|
||||
DispatchQueue.main.async {
|
||||
|
@ -224,18 +233,7 @@ extension ImageViewController {
|
|||
|
||||
self.present(activityViewController, animated: true)
|
||||
case .failure:
|
||||
let alertController = UIAlertController(
|
||||
title: nil,
|
||||
message: NSLocalizedString("attachment.unable-to-export-media", comment: ""),
|
||||
preferredStyle: .alert)
|
||||
|
||||
let okAction = UIAlertAction(
|
||||
title: NSLocalizedString("ok", comment: ""),
|
||||
style: .default) { _ in }
|
||||
|
||||
alertController.addAction(okAction)
|
||||
|
||||
self.present(alertController, animated: true)
|
||||
self.alertUnableToExportMedia()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,4 +289,19 @@ private extension ImageViewController {
|
|||
scrollView.setZoomScale(scrollView.minimumZoomScale, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
func alertUnableToExportMedia() {
|
||||
let alertController = UIAlertController(
|
||||
title: nil,
|
||||
message: NSLocalizedString("attachment.unable-to-export-media", comment: ""),
|
||||
preferredStyle: .alert)
|
||||
|
||||
let okAction = UIAlertAction(
|
||||
title: NSLocalizedString("ok", comment: ""),
|
||||
style: .default) { _ in }
|
||||
|
||||
alertController.addAction(okAction)
|
||||
|
||||
self.present(alertController, animated: true)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue