Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (64 sloc) 2.51 KB
//
// ALBPinbookActivity.m
// PinbookActivity
//
// Created by Collin Donnell on 9/27/12.
// Copyright (c) 2012 Collin Donnell. All rights reserved.
//
#import "ALBPinbookActivity.h"
NSString *const ALBActivityTypeSendToPinbook = @"ALBActivityTypeSendToPinbook";
NSString *const ALBPinbookTitleParameterKey = @"title";
NSString *const ALBPinbookTagsParameterKey = @"tags";
NSString *const ALBPinbookDescriptionParameterKey = @"description";
NSString *const ALBPinbookPrivateParameterKey = @"private";
NSString *const ALBPinbookReadLaterParameterKey = @"readlater";
@interface ALBPinbookActivity ()
@property (strong, nonatomic) NSURL *activityURL;
@end
@implementation ALBPinbookActivity
- (NSString *)activityType
{
return ALBActivityTypeSendToPinbook;
}
- (NSString *)activityTitle
{
return @"Send to Pinbook";
}
- (UIImage *)activityImage
{
return [UIImage imageNamed:@"ALBPinbookActivityMask"];
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
return activityItems.count == 1 && [[activityItems lastObject] isKindOfClass:[NSURL class]] && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"pinbook:///"]];
}
- (void)prepareWithActivityItems:(NSArray *)activityItems
{
self.activityURL = [activityItems lastObject];
}
- (void)performActivity
{
BOOL didFinish = NO;
NSMutableString *pinbookURLString = [NSMutableString stringWithFormat:@"pinbook:///add?url=%@", [self.activityURL absoluteString]];
NSMutableArray *pathComponents = [NSMutableArray array];
for (NSString *key in self.bookmarkParameters) {
id parameterValue = self.bookmarkParameters[key];
if ([parameterValue isKindOfClass:[NSNumber class]]) {
parameterValue = [parameterValue boolValue] ? @"yes" : @"no";
}
if ([parameterValue isKindOfClass:[NSString class]] && [parameterValue length]) {
[pathComponents addObject:[NSString stringWithFormat:@"%@=%@", key, parameterValue]];
}
}
NSString *parameterString = [pathComponents componentsJoinedByString:@"&"];
if ([parameterString length]) {
[pinbookURLString appendFormat:@"&%@", parameterString];
}
NSURL *pinbookURL = [NSURL URLWithString:[pinbookURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL:pinbookURL]) {
[[UIApplication sharedApplication] openURL:pinbookURL];
didFinish = YES;
}
[self activityDidFinish:didFinish];
}
@end
Something went wrong with that request. Please try again.