This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
APLFacebookProxyActivity.m
78 lines (61 loc) · 2.19 KB
/
APLFacebookProxyActivity.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// APLFacebookProxyActivity.m
//
//
// Created by Heiko Wichmann on 04.04.2013.
// Copyright (c) 2013 apploft GmbH. All rights reserved.
//
#import "APLFacebookProxyActivity.h"
#import <Social/Social.h>
@interface APLFacebookProxyActivity ()
@property (nonatomic, strong) NSArray *items;
@end
@implementation APLFacebookProxyActivity
+ (instancetype)proxyActivityIfNeeded {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
return nil;
}
// Apple's UIActivityViewController does not display a Facebook Button
// if the user is not already connected.
// We add a custom application activity here, to display a Facebook Button in this case.
// Our activity tries to present a composeViewControllerForServiceType:SLServiceTypeFacebook
// which triggers a system alert view that displays further instructions for setting the Facebook account in iOS system settings.
return [self new];
}
- (NSString *)activityTitle
{
return @"Facebook";
}
- (UIImage *)activityImage
{
UIImage *anActivityImage = [UIImage imageNamed:@"facebook-share-proxy-57.png"];
return anActivityImage;
}
- (NSString *)activityType {
return UIActivityTypePostToFacebook;
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
return YES;
}
- (void)prepareWithActivityItems:(NSArray *)activityItems {
self.items = activityItems;
}
- (UIViewController *)activityViewController
{
SLComposeViewControllerCompletionHandler aComposeViewControllerCompletionHandler = ^(SLComposeViewControllerResult result)
{
[self activityDidFinish:YES];
};
SLComposeViewController *aFacebookComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
for (id item in self.items) {
if ([item isKindOfClass:[NSString class]]) {
[aFacebookComposeViewController setInitialText:item];
} else if ([item isKindOfClass:[UIImage class]]) {
[aFacebookComposeViewController addImage:item];
}
}
[aFacebookComposeViewController setCompletionHandler:aComposeViewControllerCompletionHandler];
return aFacebookComposeViewController;
}
@end