Skip to content

Instantly share code, notes, and snippets.

@fmtonakai
Last active December 14, 2015 15:19
Show Gist options
  • Save fmtonakai/5106794 to your computer and use it in GitHub Desktop.
Save fmtonakai/5106794 to your computer and use it in GitHub Desktop.
UIActivityViewControllerでTwitterの時だけハッシュタグを追加する
#import <Foundation/Foundation.h>
@interface ActivityText : NSObject <UIActivityItemSource>
-(id)initWithText:(NSString *)text hashTag:(NSString *)hashTag;
@end
#import "ActivityText.h"
@implementation ActivityText
{
NSString *_text, *_hashTag;
}
-(id)initWithText:(NSString *)text hashTag:(NSString *)hashTag
{
self = [super init];
if (self) {
_text = text;
_hashTag = hashTag;
}
return self;
}
#pragma mark - UIActivityItemSource
-(id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
// Twitterの時だけハッシュタグをつける
if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
return [NSString stringWithFormat:@"%@ #%@", _text, _hashTag];
}
return _text;
}
-(id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
return _text;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment