-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSOPinnerActivity.m
86 lines (64 loc) · 2.58 KB
/
SOPinnerActivity.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
79
80
81
82
83
84
85
86
//
// SOPinnerActivity.m
// PinnerActivity
//
// Created by Sam Oakley on 30/12/12.
// Copyright (c) 2012 Sam Oakley. All rights reserved.
//
#import "SOPinnerActivity.h"
NSString *const SOActivityTypeSendToPinboard = @"SOActivityTypeSendToPinboard";;
NSString *const SOPinnerTitleParameterKey = @"title";
NSString *const SOPinnerTagsParameterKey = @"tags";
NSString *const SOPinnerExtendedParameterKey = @"extended";
NSString *const SOPinnerSharedParameterKey = @"shared";
NSString *const SOPinnerToReadParameterKey = @"toread";
@interface SOPinnerActivity ()
@property (strong, nonatomic) NSURL *activityURL;
@end
@implementation SOPinnerActivity
- (NSString *)activityType
{
return SOActivityTypeSendToPinboard;
}
- (NSString *)activityTitle
{
return @"Save to Pinner";
}
- (UIImage *)activityImage
{
return [UIImage imageNamed:@"SOPinnerActivityMask"];
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF.class.description == %@", [[NSURL class] description]];
BOOL containsURL = [predicate evaluateWithObject:activityItems];
return containsURL && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"pinner:///"]];
}
- (void)prepareWithActivityItems:(NSArray *)activityItems
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.class.description == %@", [[NSURL class] description]];
NSArray *URLS = [activityItems filteredArrayUsingPredicate:predicate];
NSURL* activityURL = [URLS objectAtIndex:0];
self.activityURL = activityURL;
}
- (void)performActivity
{
BOOL didFinish = NO;
NSMutableString *pinnerURLString = [NSMutableString stringWithFormat:@"pinner://bookmark?href=%@", [self.activityURL absoluteString]];
NSMutableArray *pathComponents = [NSMutableArray array];
for (NSString *key in self.bookmarkParameters) {
id parameterValue = self.bookmarkParameters[key];
[pathComponents addObject:[NSString stringWithFormat:@"%@=%@", key, parameterValue]];
}
NSString *parameterString = [pathComponents componentsJoinedByString:@"&"];
if ([parameterString length]) {
[pinnerURLString appendFormat:@"&%@", parameterString];
}
NSURL *pinnerURL = [NSURL URLWithString:[pinnerURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL:pinnerURL]) {
[[UIApplication sharedApplication] openURL:pinnerURL];
didFinish = YES;
}
[self activityDidFinish:didFinish];
}
@end