Last active
December 14, 2015 15:19
-
-
Save fmtonakai/5106794 to your computer and use it in GitHub Desktop.
UIActivityViewControllerでTwitterの時だけハッシュタグを追加する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface ActivityText : NSObject <UIActivityItemSource> | |
-(id)initWithText:(NSString *)text hashTag:(NSString *)hashTag; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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