session-ios/Signal/src/ViewControllers/AttachmentSharing.m
Matthew Chen b1624d6818 Respond to CR.
// FREEBIE
2017-10-12 16:23:48 -04:00

87 lines
2.6 KiB
Objective-C

//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "AttachmentSharing.h"
#import "TSAttachmentStream.h"
#import "Threading.h"
#import "UIUtil.h"
@implementation AttachmentSharing
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream {
OWSAssert(stream);
[self showShareUIForURL:stream.mediaURL];
}
+ (void)showShareUIForURL:(NSURL *)url {
OWSAssert(url);
[AttachmentSharing showShareUIForActivityItems:@[
url,
]];
}
+ (void)showShareUIForText:(NSString *)text
{
OWSAssert(text);
[AttachmentSharing showShareUIForActivityItems:@[
text,
]];
}
+ (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) {
DDLogDebug(@"%@ applying signal appearence", self.tag);
[UIUtil applySignalAppearence];
if (activityError) {
DDLogInfo(@"%@ Failed to share with activityError: %@", self.tag, activityError);
} else if (completed) {
DDLogInfo(@"%@ Did share with activityType: %@", self.tag, activityType);
}
}];
// Find the frontmost presented UIViewController from which to present the
// share view.
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *fromViewController = window.rootViewController;
while (fromViewController.presentedViewController) {
fromViewController = fromViewController.presentedViewController;
}
OWSAssert(fromViewController);
[fromViewController presentViewController:activityViewController
animated:YES
completion:^{
DDLogDebug(@"%@ applying default system appearence", self.tag);
[UIUtil applyDefaultSystemAppearence];
}];
});
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end