Last active
December 15, 2015 08:59
-
-
Save fmtonakai/5234731 to your computer and use it in GitHub Desktop.
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
typedef id (^ActivitySourceWrapperExecuteBlock)(UIActivityViewController* activityViewController,NSString* activityType); | |
@interface ActivitySourceWrapper : NSObject<UIActivityItemSource> | |
@property id placeholder; | |
-(id)initWithBlock:(ActivitySourceWrapperExecuteBlock)block; | |
-(id)initWithBlock:(ActivitySourceWrapperExecuteBlock)block withPlaceholder:(id)placeholder; | |
@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
@implementation ActivitySourceWrapper | |
{ | |
ActivitySourceWrapperExecuteBlock _block; | |
} | |
-(id)initWithBlock:(ActivitySourceWrapperExecuteBlock)block | |
{ | |
return [self initWithBlock:block withPlaceholder:nil]; | |
} | |
-(id)initWithBlock:(ActivitySourceWrapperExecuteBlock)block withPlaceholder:(id)placeholder | |
{ | |
self = [super init]; | |
if(self) { | |
_block = [block copy]; | |
if(placeholder) { | |
self.placeholder = placeholder; | |
} | |
} | |
return self; | |
} | |
-(id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType | |
{ | |
return _block(activityViewController,activityType); | |
} | |
-(id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController | |
{ | |
if (self.placeholder) { | |
return self.placeholder; | |
} | |
return @""; | |
} | |
@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 "ActivitySourceWrapper.h" | |
@implementation ActivitySourceWrapperTest | |
+(void)presentShareViewController:(UIViewController *)controller withText:(NSString *)text withUrl:(NSURL *)url | |
{ | |
id shareTextActivitySource = [[ActivitySourceWrapper alloc] initWithBlock:^id(UIActivityViewController *activityViewController, NSString *activityType) { | |
NSString *shareText = text; | |
if([activityType isEqualToString:UIActivityTypePostToTwitter]) { | |
shareText = [shareText stringByAppendingString:@" #ハッシュタグ"]; | |
} | |
return shareText; | |
}]; | |
id shareURLyActivitySource = [[ActivitySourceWrapper alloc] initWithBlock:^id(UIActivityViewController *activityViewController, NSString *activityType) { | |
return url; | |
}]; | |
NSArray *activitySourceArray = @[shareTextActivitySource, shareURLyActivitySource]; | |
UIActivityViewController *actViewCtr = [[UIActivityViewController alloc]initWithActivityItems:activitySourceArray applicationActivities:nil]; | |
[controller presentViewController:actViewCtr animated:YES completion:^{}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment