session-ios/SignalMessaging/attachments/AttachmentSharing.m

87 lines
2.5 KiB
Mathematica
Raw Normal View History

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"
#import "UIUtil.h"
2017-12-04 22:09:26 +01:00
#import <SignalServiceKit/AppContext.h>
2017-12-08 17:50:35 +01:00
#import <SignalServiceKit/TSAttachmentStream.h>
#import <SignalServiceKit/Threading.h>
2017-02-16 23:59:40 +01:00
@implementation AttachmentSharing
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream
{
2017-02-16 23:59:40 +01:00
OWSAssert(stream);
2017-10-10 22:13:54 +02:00
[self showShareUIForURL:stream.mediaURL];
2017-02-16 23:59:40 +01:00
}
+ (void)showShareUIForURL:(NSURL *)url
{
OWSAssert(url);
2017-02-16 23:59:40 +01:00
2017-10-10 22:13:54 +02:00
[AttachmentSharing showShareUIForActivityItems:@[
url,
]];
}
2017-10-12 19:48:09 +02:00
+ (void)showShareUIForText:(NSString *)text
{
OWSAssert(text);
2017-10-12 19:48:09 +02:00
[AttachmentSharing showShareUIForActivityItems:@[
text,
]];
2017-10-12 19:48:09 +02:00
}
2018-01-18 19:39:52 +01:00
#ifdef DEBUG
+ (void)showShareUIForUIImage:(UIImage *)image
{
OWSAssert(image);
[AttachmentSharing showShareUIForActivityItems:@[
image,
]];
}
#endif
2017-10-10 22:13:54 +02:00
+ (void)showShareUIForActivityItems:(NSArray *)activityItems
{
OWSAssert(activityItems);
DispatchMainThreadSafe(^{
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[]];
[activityViewController setCompletionWithItemsHandler:^(UIActivityType __nullable activityType,
BOOL completed,
NSArray *__nullable returnedItems,
NSError *__nullable activityError) {
2017-11-08 20:04:51 +01:00
DDLogDebug(@"%@ applying signal appearence", self.logTag);
2017-10-10 22:13:54 +02:00
[UIUtil applySignalAppearence];
2017-10-10 22:13:54 +02:00
if (activityError) {
2017-11-08 20:04:51 +01:00
DDLogInfo(@"%@ Failed to share with activityError: %@", self.logTag, activityError);
2017-10-10 22:13:54 +02:00
} else if (completed) {
2017-11-08 20:04:51 +01:00
DDLogInfo(@"%@ Did share with activityType: %@", self.logTag, activityType);
2017-10-10 22:13:54 +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
}
2017-10-10 22:13:54 +02:00
OWSAssert(fromViewController);
[fromViewController presentViewController:activityViewController
animated:YES
completion:^{
2017-11-08 20:04:51 +01:00
DDLogDebug(@"%@ applying default system appearence", self.logTag);
2017-10-10 22:13:54 +02:00
[UIUtil applyDefaultSystemAppearence];
}];
});
}
2017-02-16 23:59:40 +01:00
@end