-
Notifications
You must be signed in to change notification settings - Fork 23
/
Social.m
60 lines (42 loc) · 1.63 KB
/
Social.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
//
// Social.m
//
// Cameron Lerch
// Sponsored by Brightflock: http://brightflock.com
//
#import "Social.h"
@interface Social ()
@end
@implementation Social
- (void)available:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
BOOL avail = false;
if (NSClassFromString(@"UIActivityViewController")) {
avail = true;
}
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:avail];
[self writeJavascript:[pluginResult toSuccessCallbackString:[arguments objectAtIndex:0]]];
}
- (void)share:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
if (!NSClassFromString(@"UIActivityViewController")) {
return;
}
NSString *text = [arguments objectAtIndex:1];
NSString *imageName = [arguments objectAtIndex:2];
UIImage *image = nil;
if (imageName) {
image = [UIImage imageNamed:imageName];
}
NSString *urlString = [arguments objectAtIndex:3];
NSURL *url = nil;
if (urlString) {
url = [NSURL URLWithString:urlString];
}
NSArray *activityItems = [[NSArray alloc] initWithObjects:text, image, url, nil];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
[self.viewController presentViewController:activityVC animated:YES completion:nil];
}
@end