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

73 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"
2017-02-16 23:59:40 +01:00
@implementation AttachmentSharing
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream {
OWSAssert(stream);
dispatch_async(dispatch_get_main_queue(), ^{
[AttachmentSharing showShareUIForURL:stream.mediaURL];
2017-02-16 23:59:40 +01:00
});
}
+ (void)showShareUIForURL:(NSURL *)url {
2017-02-16 23:59:40 +01:00
AssertIsOnMainThread();
OWSAssert(url);
2017-02-16 23:59:40 +01:00
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[
url,
]
2017-02-16 23:59:40 +01:00
applicationActivities:@[
]];
2017-02-16 23:59:40 +01:00
[activityViewController setCompletionWithItemsHandler:^(UIActivityType __nullable activityType,
BOOL completed,
NSArray *__nullable returnedItems,
NSError *__nullable activityError) {
DDLogDebug(@"%@ applying signal appearence", self.tag);
[UIUtil applySignalAppearence];
2017-02-16 23:59:40 +01:00
if (activityError) {
DDLogInfo(@"%@ Failed to share with activityError: %@", self.tag, activityError);
} else if (completed) {
DDLogInfo(@"%@ Did share with activityType: %@", self.tag, activityType);
}
}];
2017-02-16 23:59:40 +01: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;
}
OWSAssert(fromViewController);
[fromViewController presentViewController:activityViewController
animated:YES
completion:^{
DDLogDebug(@"%@ applying default system appearence", self.tag);
[UIUtil applyDefaultSystemAppearence];
}];
2017-02-16 23:59:40 +01:00
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end