Begin from iOS6, Apple simplify the share process by using UIActivityViewController.
The thing is that, Twitter is only allow up to 140 characters on a post,
thus we may need to customize the share text for Twitter.

One of the way is to subclass the UIActivityItemProvider. Here is
how you can do it:

MyActivityItemProvider.h

1
2
3
4
5
#import <UIKit/UIKit.h>
@interface MyActivityItemProvider : UIActivityItemProvider
@end

MyActivityItemProvider.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#import "MyActivityItemProvider.h"
@implementation MyActivityItemProvider
// 1.
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
// 2.
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
return @"Facebook: testing 123";
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
return @"Twitter: testing 123";
}
return @"No provider";
}
@end

MyViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
// 3.
MyActivityItemProvider *message = [[MyActivityItemProvider alloc] init];
NSArray *activityItems;
if (myImage != nil) {
activityItems = @[message, myImage];
} else {
activityItems = @[message];
}
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
  1. Override activityViewController:itemForActivityType:.
  2. Customize message for each provider if you want to.
  3. Just treat it as a message, assign it together with image (if you have one). The UIActivityViewController will then pick the correct message for corresponding provider.