2017-02-16 23:59:40 +01:00
|
|
|
//
|
2018-01-18 19:39:52 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-02-16 23:59:40 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "AttachmentSharing.h"
|
2017-04-11 18:14:59 +02:00
|
|
|
#import "UIUtil.h"
|
2020-11-11 01:50:01 +01:00
|
|
|
|
|
|
|
#import <SignalUtilitiesKit/AppContext.h>
|
|
|
|
#import <SignalUtilitiesKit/TSAttachmentStream.h>
|
2017-02-16 23:59:40 +01:00
|
|
|
|
2018-03-02 20:29:53 +01:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-02-16 23:59:40 +01:00
|
|
|
@implementation AttachmentSharing
|
|
|
|
|
2018-11-05 17:07:00 +01:00
|
|
|
+ (void)showShareUIForAttachments:(NSArray<TSAttachmentStream *> *)attachmentStreams
|
|
|
|
completion:(nullable AttachmentSharingCompletion)completion
|
|
|
|
{
|
|
|
|
OWSAssertDebug(attachmentStreams.count > 0);
|
|
|
|
|
|
|
|
NSMutableArray<NSURL *> *urls = [NSMutableArray new];
|
|
|
|
for (TSAttachmentStream *attachmentStream in attachmentStreams) {
|
|
|
|
[urls addObject:attachmentStream.originalMediaURL];
|
|
|
|
}
|
|
|
|
|
|
|
|
[AttachmentSharing showShareUIForActivityItems:urls completion:completion];
|
|
|
|
}
|
|
|
|
|
2017-12-07 01:29:12 +01:00
|
|
|
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream
|
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(stream);
|
2017-02-16 23:59:40 +01:00
|
|
|
|
2018-09-04 16:25:42 +02:00
|
|
|
[self showShareUIForURL:stream.originalMediaURL];
|
2017-02-16 23:59:40 +01:00
|
|
|
}
|
|
|
|
|
2017-12-07 01:29:12 +01:00
|
|
|
+ (void)showShareUIForURL:(NSURL *)url
|
2018-03-02 20:29:53 +01:00
|
|
|
{
|
|
|
|
[self showShareUIForURL:url completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion
|
2017-12-07 01:29:12 +01:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(url);
|
2018-11-12 16:44:39 +01:00
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
[AttachmentSharing showShareUIForActivityItems:@[
|
2018-11-12 16:44:39 +01:00
|
|
|
url,
|
|
|
|
]
|
|
|
|
completion:completion];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)showShareUIForURLs:(NSArray<NSURL *> *)urls completion:(nullable AttachmentSharingCompletion)completion
|
|
|
|
{
|
|
|
|
OWSAssertDebug(urls.count > 0);
|
|
|
|
|
|
|
|
[AttachmentSharing showShareUIForActivityItems:urls
|
2018-03-02 20:29:53 +01:00
|
|
|
completion:completion];
|
2017-10-10 22:13:54 +02:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:48:09 +02:00
|
|
|
+ (void)showShareUIForText:(NSString *)text
|
2018-03-02 20:29:53 +01:00
|
|
|
{
|
|
|
|
[self showShareUIForText:text completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion
|
2017-10-12 19:48:09 +02:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(text);
|
2017-12-07 01:29:12 +01:00
|
|
|
|
2017-10-12 19:48:09 +02:00
|
|
|
[AttachmentSharing showShareUIForActivityItems:@[
|
2017-12-07 01:29:12 +01:00
|
|
|
text,
|
2018-03-02 20:29:53 +01:00
|
|
|
]
|
|
|
|
completion:completion];
|
2017-10-12 19:48:09 +02:00
|
|
|
}
|
|
|
|
|
2018-01-18 19:39:52 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
+ (void)showShareUIForUIImage:(UIImage *)image
|
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(image);
|
2018-01-18 19:39:52 +01:00
|
|
|
|
|
|
|
[AttachmentSharing showShareUIForActivityItems:@[
|
|
|
|
image,
|
2018-03-02 20:29:53 +01:00
|
|
|
]
|
|
|
|
completion:nil];
|
2018-01-18 19:39:52 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-02 20:29:53 +01:00
|
|
|
+ (void)showShareUIForActivityItems:(NSArray *)activityItems completion:(nullable AttachmentSharingCompletion)completion
|
2017-10-10 22:13:54 +02:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(activityItems);
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
DispatchMainThreadSafe(^{
|
|
|
|
UIActivityViewController *activityViewController =
|
|
|
|
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[]];
|
|
|
|
|
|
|
|
[activityViewController setCompletionWithItemsHandler:^(UIActivityType __nullable activityType,
|
|
|
|
BOOL completed,
|
|
|
|
NSArray *__nullable returnedItems,
|
|
|
|
NSError *__nullable activityError) {
|
2017-04-11 18:14:59 +02:00
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
if (activityError) {
|
2018-08-27 18:51:32 +02:00
|
|
|
OWSLogInfo(@"Failed to share with activityError: %@", activityError);
|
2017-10-10 22:13:54 +02:00
|
|
|
} else if (completed) {
|
2018-08-27 18:51:32 +02:00
|
|
|
OWSLogInfo(@"Did share with activityType: %@", activityType);
|
2017-10-10 22:13:54 +02:00
|
|
|
}
|
2018-03-02 20:29:53 +01:00
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
DispatchMainThreadSafe(completion);
|
|
|
|
}
|
2017-10-10 22:13:54 +02:00
|
|
|
}];
|
2017-04-11 18:14:59 +02:00
|
|
|
|
2017-12-04 22:09:26 +01:00
|
|
|
UIViewController *fromViewController = CurrentAppContext().frontmostViewController;
|
2017-10-10 22:13:54 +02:00
|
|
|
while (fromViewController.presentedViewController) {
|
|
|
|
fromViewController = fromViewController.presentedViewController;
|
2017-02-16 23:59:40 +01:00
|
|
|
}
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(fromViewController);
|
2018-06-30 00:17:49 +02:00
|
|
|
[fromViewController presentViewController:activityViewController animated:YES completion:nil];
|
2017-10-10 22:13:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-16 23:59:40 +01:00
|
|
|
@end
|
2018-03-02 20:29:53 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|