Override UIActivityViewController default behaviour

user376845 picture user376845 · Oct 7, 2012 · Viewed 8k times · Source

In the Photos app on the iPhone, when you select the Mail sharing option, the photo animates into the modal view controller that slides up. How is it possible to modify the behaviour of the built-in UIActivities? For example, I'd like to be able to set the subject field of the mail composer.

Answer

brynbodayle picture brynbodayle · Oct 17, 2012

Unfortunately, customizing the subject field of the UIActivityViewController mail composer is not working yet.

There is a documented and reported bug regarding trying to customize this discussed here:

iphone - How do I set recipients for UIActivityViewController in iOS 6?


If this were working, according to the documentation, you would be able to customize these mail composer fields:

UIActivityTypeMail: The object posts the provided content to a new email message. When using this service, you can provide NSString and UIImage objects and NSURL objects pointing to local files as data for the activity items. You may also specify NSURL objects whose contents use the mailto scheme.

So using the mailto scheme, when it is working, you should be able to customize those fields like this:

    NSString *text = @"My mail text";
    NSURL *recipients = [NSURL URLWithString:@"mailto:[email protected]?subject=Here-is-a-Subject"];
    NSArray *activityItems = @[text, recipients];

    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityController animated:YES completion:nil];

If your looking for other ways to customize the UIActivityViewControllerthere is an excellent example project here:

https://github.com/russj/ios6ShareDemo