session-ios/Signal/src/ViewControllers/AttachmentSharing.m

76 lines
2.5 KiB
Mathematica
Raw Normal View History

2017-02-16 23:59:40 +01:00
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "AttachmentSharing.h"
#import "TSAttachmentStream.h"
#import "UIUtil.h"
#import <SignalServiceKit/Threading.h>
2017-02-16 23:59:40 +01:00
@implementation AttachmentSharing
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream {
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);
[AttachmentSharing showShareUIForActivityItems:@[
text,
]];
}
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-10-10 22:13:54 +02:00
// 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;
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