mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01: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,17 +193,26 @@ extension ImageViewController {
|
|||
}
|
||||
|
||||
func presentActivityViewController() {
|
||||
if let image = imageView.image {
|
||||
let activityViewController = UIActivityViewController(
|
||||
activityItems: [NSItemProvider(object: image)],
|
||||
applicationActivities: [])
|
||||
if let imageData = imageView.image?.sd_imageData(), let url = imageURL ?? viewModel?.attachment.url.url {
|
||||
let tempURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||
.appendingPathComponent(url.lastPathComponent)
|
||||
|
||||
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||
activityViewController.popoverPresentationController?
|
||||
.barButtonItem = parent?.navigationItem.rightBarButtonItem
|
||||
do {
|
||||
try imageData.write(to: tempURL)
|
||||
|
||||
let activityViewController = UIActivityViewController(
|
||||
activityItems: [tempURL],
|
||||
applicationActivities: [])
|
||||
|
||||
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||
activityViewController.popoverPresentationController?
|
||||
.barButtonItem = parent?.navigationItem.rightBarButtonItem
|
||||
}
|
||||
|
||||
present(activityViewController, animated: true)
|
||||
} catch {
|
||||
alertUnableToExportMedia()
|
||||
}
|
||||
|
||||
present(activityViewController, animated: true)
|
||||
} 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