我接受了這個答案,併爲它做了一個簡單的類。默認消息將通過除Twitter之外的其他共享出口來顯示,而對於Twitter語言,如果散列字列表中的Twitter語言出現在默認消息中,則它們將與哈希一起顯示。我想我會分享給任何需要它的人。謝謝克里斯託弗!
用法:
TwitterHashActivityItemProvider *twit = [[TwitterHashActivityItemProvider alloc] initWithDefaultText:@"I really like stackoverflow and code"
hashWords:@[@"stackoverflow", @"code"]];
NSArray *items = @[twit];
UIActivityViewController *act = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
部首:
@interface TwitterHashActivityItemProvider : UIActivityItemProvider
- (id)initWithDefaultText:(NSString*)text hashWords:(NSArray*)hashItems;
@property (nonatomic,strong) NSArray *hashItems;
@end
實現:一個UIActivityItemProvider子類的
#import "TwitterHashActivityItemProvider.h"
@implementation TwitterHashActivityItemProvider
- (id)initWithDefaultText:(NSString*)text hashWords:(NSArray*)hashItems;
{
self = [super initWithPlaceholderItem:text];
if (self)
{
self.hashItems = hashItems;
}
return self;
}
- (id)item
{
if ([self.placeholderItem isKindOfClass:[NSString class]])
{
NSString *outputString = [self.placeholderItem copy];
// twitter gets some hash tags!
if (self.activityType == UIActivityTypePostToTwitter)
{
// go through each potential hash item and augment the main string
for (NSString *hashItem in self.hashItems)
{
NSString *hashed = [@"#" stringByAppendingString:hashItem];
outputString = [outputString stringByReplacingOccurrencesOfString:hashItem withString:hashed];
}
}
return outputString;
}
// else we didn't actually provide a string...oops...just return the placeholder
return self.placeholderItem;
}
@end
非常感謝您對這個答案:) – Ertai
一些示例代碼將是巨大的充實這個答案出來 –
偉大的答案,謝謝。下面添加了一個快速示例。 – pkorosec