Figuring out which icon was clicked on in UIActivityViewController

sirab333 picture sirab333 · May 22, 2013 · Viewed 11.6k times · Source

Using the "Social" Framework, when presenting the modal UIActivityViewController that displays all the usual social-media icons, is there a way to find out exactly which icon the user clicked on? Meaning, if they chose Twitter, Facebook, Mail, Message, etc?

I was expecting to possibly see some delegate methods for this class in the Docs but I don't see anything.

Anybody got any ideas?

Answer

rmaddy picture rmaddy · May 22, 2013

The UIActivityViewController has the completionHandler property. Implement this handler to be notified.

UIActivityViewController *avc = ...;
avc.completionHandler = ^(NSString *activityType, BOOL completed) {
    if (completed) {
        NSLog(@"The selected activity was %@", activityType);
    }
};