mirror of
https://github.com/metabolist/metatext
synced 2025-01-04 22:06:48 +01:00
Fix saving images
This commit is contained in:
parent
f7ff1b8284
commit
99678e43fb
@ -193,17 +193,26 @@ extension ImageViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func presentActivityViewController() {
|
func presentActivityViewController() {
|
||||||
if let image = imageView.image {
|
if let imageData = imageView.image?.sd_imageData(), let url = imageURL ?? viewModel?.attachment.url.url {
|
||||||
let activityViewController = UIActivityViewController(
|
let tempURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||||
activityItems: [NSItemProvider(object: image)],
|
.appendingPathComponent(url.lastPathComponent)
|
||||||
applicationActivities: [])
|
|
||||||
|
|
||||||
if UIDevice.current.userInterfaceIdiom == .pad {
|
do {
|
||||||
activityViewController.popoverPresentationController?
|
try imageData.write(to: tempURL)
|
||||||
.barButtonItem = parent?.navigationItem.rightBarButtonItem
|
|
||||||
|
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 {
|
} else if let asset = playerView.player?.currentItem?.asset as? AVURLAsset {
|
||||||
asset.exportWithoutAudioTrack { result in
|
asset.exportWithoutAudioTrack { result in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@ -224,18 +233,7 @@ extension ImageViewController {
|
|||||||
|
|
||||||
self.present(activityViewController, animated: true)
|
self.present(activityViewController, animated: true)
|
||||||
case .failure:
|
case .failure:
|
||||||
let alertController = UIAlertController(
|
self.alertUnableToExportMedia()
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,4 +289,19 @@ private extension ImageViewController {
|
|||||||
scrollView.setZoomScale(scrollView.minimumZoomScale, animated: true)
|
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 New Issue
Block a user