1

I plan to use UIActivityViewController to share text to twitter, etc. I need to share different text to twitter, email, etc. As a result, I need to change text dynamically based on user selection. May I know a way to do?

I know a way like this. But it is only after action is done and I can't change text. UIActivityViewController - is there a way to know which activity was selected?

Community
  • 1
  • 1
Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120

1 Answers1

2

You can implement an UIActivityItemSource and its itemForActivityType: method to provide content to match the user's selection.

This is explained on NSHipster. For your convenience I copy/pasted the relevant Objective-C code and description:

One example of how this could be used is to customize a message, depending on whether it's to be shared on Facebook or Twitter.

if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
    return NSLocalizedString(@"Like this!",nil);
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
    return NSLocalizedString(@"Retweet this!",nil);
} else {
    return nil;
}
neowinston
  • 7,584
  • 10
  • 52
  • 83
Clafou
  • 15,250
  • 7
  • 58
  • 89