diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index a802e285b..68ce5048e 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -486,6 +486,12 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc // Open the document if possible guard let url = viewItem.attachmentStream?.originalMediaURL else { return } let shareVC = UIActivityViewController(activityItems: [ url ], applicationActivities: nil) + if UIDevice.current.isIPad { + shareVC.excludedActivityTypes = [] + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = self.view + shareVC.popoverPresentationController?.sourceRect = self.view.bounds + } navigationController!.present(shareVC, animated: true, completion: nil) } case .textOnlyMessage: diff --git a/Session/Conversations/ConversationViewItem.h b/Session/Conversations/ConversationViewItem.h index 8aeaccd01..46ba1edaa 100644 --- a/Session/Conversations/ConversationViewItem.h +++ b/Session/Conversations/ConversationViewItem.h @@ -131,7 +131,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType); - (void)copyMediaAction; - (void)copyTextAction; -- (void)shareMediaAction; - (void)saveMediaAction; - (void)deleteLocallyAction; - (void)deleteRemotelyAction; diff --git a/Session/Conversations/ConversationViewItem.m b/Session/Conversations/ConversationViewItem.m index 4ebdd168a..352df93f1 100644 --- a/Session/Conversations/ConversationViewItem.m +++ b/Session/Conversations/ConversationViewItem.m @@ -798,42 +798,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; } -- (void)shareMediaAction -{ - if (self.attachmentPointer != nil) { - OWSFailDebug(@"Can't share not-yet-downloaded attachment"); - return; - } - - switch (self.messageCellType) { - case OWSMessageCellType_Unknown: - case OWSMessageCellType_TextOnlyMessage: - case OWSMessageCellType_Audio: - case OWSMessageCellType_GenericAttachment: - [AttachmentSharing showShareUIForAttachment:self.attachmentStream]; - break; - case OWSMessageCellType_MediaMessage: { - // TODO: We need a "canShareMediaAction" method. - OWSAssertDebug(self.mediaAlbumItems); - NSMutableArray *attachmentStreams = [NSMutableArray new]; - for (ConversationMediaAlbumItem *mediaAlbumItem in self.mediaAlbumItems) { - if (mediaAlbumItem.attachmentStream && mediaAlbumItem.attachmentStream.isValidVisualMedia) { - [attachmentStreams addObject:mediaAlbumItem.attachmentStream]; - } - } - if (attachmentStreams.count < 1) { - OWSFailDebug(@"Can't share media album; no valid items."); - return; - } - [AttachmentSharing showShareUIForAttachments:attachmentStreams completion:nil]; - break; - } - case OWSMessageCellType_OversizeTextDownloading: - OWSFailDebug(@"Can't share not-yet-downloaded attachment"); - return; - } -} - - (BOOL)canCopyMedia { if (self.attachmentPointer != nil) { diff --git a/Session/Conversations/LongTextViewController.swift b/Session/Conversations/LongTextViewController.swift index ed8e043f8..5f214ffa9 100644 --- a/Session/Conversations/LongTextViewController.swift +++ b/Session/Conversations/LongTextViewController.swift @@ -165,6 +165,13 @@ public class LongTextViewController: OWSViewController { // MARK: - Actions @objc func shareButtonPressed() { - AttachmentSharing.showShareUI(forText: fullText) + let shareVC = UIActivityViewController(activityItems: [ fullText ], applicationActivities: nil) + if UIDevice.current.isIPad { + shareVC.excludedActivityTypes = [] + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = self.view + shareVC.popoverPresentationController?.sourceRect = self.view.bounds + } + self.present(shareVC, animated: true, completion: nil) } } diff --git a/Session/DMs/NewDMVC.swift b/Session/DMs/NewDMVC.swift index 0f0ce99a6..9c501418e 100644 --- a/Session/DMs/NewDMVC.swift +++ b/Session/DMs/NewDMVC.swift @@ -232,7 +232,7 @@ private final class EnterPublicKeyVC : UIViewController { // Share button let shareButton = Button(style: .unimportant, size: .medium) shareButton.setTitle(NSLocalizedString("share", comment: ""), for: UIControl.State.normal) - shareButton.addTarget(self, action: #selector(sharePublicKey(_:)), for: UIControl.Event.touchUpInside) + shareButton.addTarget(self, action: #selector(sharePublicKey), for: UIControl.Event.touchUpInside) // Button container buttonContainer.addArrangedSubview(copyButton) buttonContainer.addArrangedSubview(shareButton) @@ -330,12 +330,13 @@ private final class EnterPublicKeyVC : UIViewController { Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(enableCopyButton), userInfo: nil, repeats: false) } - @objc private func sharePublicKey(_ sender: UIButton) { + @objc private func sharePublicKey() { let shareVC = UIActivityViewController(activityItems: [ getUserHexEncodedPublicKey() ], applicationActivities: nil) if UIDevice.current.isIPad { shareVC.excludedActivityTypes = [] - shareVC.popoverPresentationController?.sourceView = sender - shareVC.popoverPresentationController?.sourceRect = sender.bounds + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = self.view + shareVC.popoverPresentationController?.sourceRect = self.view.bounds } NewDMVC.navigationController!.present(shareVC, animated: true, completion: nil) } diff --git a/Session/Media Viewing & Editing/MediaPageViewController.swift b/Session/Media Viewing & Editing/MediaPageViewController.swift index 9301d4f57..aa932fd27 100644 --- a/Session/Media Viewing & Editing/MediaPageViewController.swift +++ b/Session/Media Viewing & Editing/MediaPageViewController.swift @@ -380,8 +380,20 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou } let attachmentStream = currentViewController.galleryItem.attachmentStream - - AttachmentSharing.showShareUI(forAttachment: attachmentStream) { activityType in + + let shareVC = UIActivityViewController(activityItems: [ attachmentStream.originalMediaURL! ], applicationActivities: nil) + if UIDevice.current.isIPad { + shareVC.excludedActivityTypes = [] + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = self.view + shareVC.popoverPresentationController?.sourceRect = self.view.bounds + } + shareVC.completionWithItemsHandler = { activityType, completed, returnedItems, activityError in + if let activityError = activityError { + SNLog("Failed to share with activityError: \(activityError)") + } else if completed { + SNLog("Did share with activityType: \(activityType.debugDescription)") + } guard let activityType = activityType, activityType == .saveToCameraRoll, let tsMessage = currentViewController.galleryItem.message as? TSIncomingMessage, let thread = tsMessage.thread as? TSContactThread else { return } let message = DataExtractionNotification() @@ -389,8 +401,8 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou Storage.write { transaction in MessageSender.send(message, in: thread, using: transaction) } - } + self.present(shareVC, animated: true, completion: nil) } @objc diff --git a/Session/Settings/QRCodeVC.swift b/Session/Settings/QRCodeVC.swift index 158b88927..80aaf80f7 100644 --- a/Session/Settings/QRCodeVC.swift +++ b/Session/Settings/QRCodeVC.swift @@ -210,6 +210,12 @@ private final class ViewMyQRCodeVC : UIViewController { @objc private func shareQRCode() { let qrCode = QRCode.generate(for: getUserHexEncodedPublicKey(), hasBackground: true) let shareVC = UIActivityViewController(activityItems: [ qrCode ], applicationActivities: nil) + if UIDevice.current.isIPad { + shareVC.excludedActivityTypes = [] + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = self.view + shareVC.popoverPresentationController?.sourceRect = self.view.bounds + } qrCodeVC.navigationController!.present(shareVC, animated: true, completion: nil) } } diff --git a/Session/Settings/SettingsVC.swift b/Session/Settings/SettingsVC.swift index b85f32091..ef9b4e0e4 100644 --- a/Session/Settings/SettingsVC.swift +++ b/Session/Settings/SettingsVC.swift @@ -491,6 +491,12 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate { @objc private func sharePublicKey() { let shareVC = UIActivityViewController(activityItems: [ getUserHexEncodedPublicKey() ], applicationActivities: nil) + if UIDevice.current.isIPad { + shareVC.excludedActivityTypes = [] + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = self.view + shareVC.popoverPresentationController?.sourceRect = self.view.bounds + } navigationController!.present(shareVC, animated: true, completion: nil) } @@ -526,6 +532,12 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate { @objc private func sendInvitation() { let invitation = "Hey, I've been using Session to chat with complete privacy and security. Come join me! Download it at https://getsession.org/. My Session ID is \(getUserHexEncodedPublicKey()) !" let shareVC = UIActivityViewController(activityItems: [ invitation ], applicationActivities: nil) + if UIDevice.current.isIPad { + shareVC.excludedActivityTypes = [] + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = self.view + shareVC.popoverPresentationController?.sourceRect = self.view.bounds + } navigationController!.present(shareVC, animated: true, completion: nil) } diff --git a/Session/Settings/ShareLogsModal.swift b/Session/Settings/ShareLogsModal.swift index 10f3f799e..0a93acff1 100644 --- a/Session/Settings/ShareLogsModal.swift +++ b/Session/Settings/ShareLogsModal.swift @@ -64,7 +64,16 @@ final class ShareLogsModal : Modal { if let latestLogFilePath = logFilePaths.first { let latestLogFileURL = URL(fileURLWithPath: latestLogFilePath) self.dismiss(animated: true, completion: { - AttachmentSharing.showShareUI(for: latestLogFileURL) + if let vc = CurrentAppContext().frontmostViewController() { + let shareVC = UIActivityViewController(activityItems: [ latestLogFileURL ], applicationActivities: nil) + if UIDevice.current.isIPad { + shareVC.excludedActivityTypes = [] + shareVC.popoverPresentationController?.permittedArrowDirections = [] + shareVC.popoverPresentationController?.sourceView = vc.view + shareVC.popoverPresentationController?.sourceRect = vc.view.bounds + } + vc.present(shareVC, animated: true, completion: nil) + } }) } }