Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial Commit.

  • Loading branch information...
commit f1a24cdf03bd6f4120a75168ba5ed5bfa1e888ea 0 parents
@collindonnell authored
37 ALBPinbookActivity.h
@@ -0,0 +1,37 @@
+//
+// ALBPinbookActivity.h
+// PinbookActivity
+//
+// Created by Collin Donnell on 9/27/12.
+// Copyright (c) 2012 Collin Donnell. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+// The activity type
+extern NSString *const ALBActivityTypeSendToPinbook;
+
+// Parameter keys for settings things besides the URL, like title, tags, etc.
+// Strings:
+extern NSString *const ALBPinbookTitleParameterKey;
+extern NSString *const ALBPinbookTagsParameterKey; // Tags are a string separated by spaces.
+extern NSString *const ALBPinbookDescriptionParameterKey;
+// Booleans:
+extern NSString *const ALBPinbookPrivateParameterKey;
+extern NSString *const ALBPinbookReadLaterParameterKey;
+
+@interface ALBPinbookActivity : UIActivity
+
+@property (strong, nonatomic) NSDictionary *bookmarkParameters;
+
+@end
+
+/* Example
+
+ ALBPinbookActivity *pinbookActivity = [[ALBPinbookActivity alloc] init];
+ pinbookActivity.bookmarkParameters = @{ALBPinbookTitleParameterKey : @"Apple", ALBPinbookTagsParameterKey : @"companies mac iphone", ALBPinbookDescriptionParameterKey : @"They make nice things.", ALBPinbookPrivateParameterKey : @(YES), ALBPinbookReadLaterParameterKey : @(NO)};
+
+ UIActivityViewController *viewController = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL URLWithString:@"http://apple.com"]] applicationActivities:@[pinbookActivity]];
+ [self presentViewController:viewController animated:YES completion:nil];
+
+*/
85 ALBPinbookActivity.m
@@ -0,0 +1,85 @@
+//
+// 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
BIN  ALBPinbookActivityMask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  ALBPinbookActivityMask@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 README.md
@@ -0,0 +1,29 @@
+# ALBPinbookActivity
+ALBPinbookActivity is a UIActivity subclass which allows developers to send bookmark information to Pinbook so that it can be presented as an option in a UIActivityViewController whenever a URL is shared, and added to the users Pinboard account.
+
+## Adding to a Project
+Add the following four files to your project:
+
+* ALBPinbookActivity.h
+* ALBPinbookActivity.m
+* ALBPinbookActivityMask.png
+* ALBPinbookActivityMask@2x.png
+
+## Use
+Just create a new ALBPinbookActivity object and use it with a UIActivityViewController. Pinbook will appear as an option only if the user has it installed on their device.
+
+Optionally, set the `bookmarkParameters` property using an NSDictionary to pre-fill Pinbook’s fields with any information you like, as shown in the following example:
+
+ ALBPinbookActivity *activity = [[ALBPinbookActivity alloc] init];
+ activity.bookmarkParameters = @{ALBPinbookTitleParameterKey : @"Apple", ALBPinbookTagsParameterKey : @"companies mac iphone", ALBPinbookDescriptionParameterKey : @"They make nice things.", ALBPinbookPrivateParameterKey : @(YES), ALBPinbookReadLaterParameterKey : @(NO)};
+
+ UIActivityViewController *viewController = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL URLWithString:@"http://apple.com"]] applicationActivities:@[activity]];
+ [self presentViewController:viewController animated:YES completion:nil];
+
+## Parameter Keys
+
+* `ALBPinbookTitleParameterKey`: Any string.
+* `ALBPinbookTagsParameterKey`: A string of tags separated by spaces.
+* `ALBPinbookDescriptionParameterKey`: Any string.
+* `ALBPinbookPrivateParameterKey`: BOOL (YES/NO).
+* `ALBPinbookReadLaterParameterKey`: BOOL (YES/NO).
Please sign in to comment.
Something went wrong with that request. Please try again.