Tomé esta respuesta e hice una clase simple para ello. El mensaje predeterminado se verá compartiendo puntos de venta que no sean Twitter, y las palabras de Twitter dentro de la matriz de hashWords aparecerán con valores hash si están presentes en el mensaje predeterminado. Pensé que podría compartirlo con cualquier otra persona que lo necesite. Gracias Christopher!
Uso:
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];
Cabecera:
@interface TwitterHashActivityItemProvider : UIActivityItemProvider
- (id)initWithDefaultText:(NSString*)text hashWords:(NSArray*)hashItems;
@property (nonatomic,strong) NSArray *hashItems;
@end
Implementación:
#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
Muchas gracias por esta respuesta :) – Ertai
un código de ejemplo sería grande para dar cuerpo a cabo esta respuesta –
Gran respuesta, gracias. Se agregó un rápido ejemplo a continuación. – pkorosec