IOS/Objective-C: UIActivityItemSource Protocol for customizing share messages with UIActivityViewController

791 views Asked by At

Apple Docs say that you can use the UIActivityItemSource protocol to customize messages shared with the UIActivityViewController in lieu of a UIActivityItemProvider Object:

UIActivityItemSource

You can use this protocol in situations where you want to provide the data from one of your app’s existing objects instead of creating a separate UIActivityItemProvider object.

I have adopted this protocol, however, the delegate methods such as the one below do not seem to be firing. Can anyone confirm this should work and, if so, point me toward what I might be missing? Thanks in advance for any suggestions.

-(NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(UIActivityType)activityType
{
    NSLog(@"DELEGATE METHOD CALLED");//Not logging to console 

    if (activityType == UIActivityTypeMessage) {
        return @"My message";
    } else if (activityType == UIActivityTypeMail) {
        return @"My email text";
    }
else {
    return @"My default text";
}
}
1

There are 1 answers

1
clemens On BEST ANSWER

Yes, this delegate method works for me, and the delegate method is called. I create the activity item controller with the following code:

NSArray *theItems = @[ self ];
UIActivityViewController *theController = [[UIActivityViewController alloc] initWithActivityItems:theItems applicationActivities:nil];

theController.popoverPresentationController.barButtonItem = self.shareButton;
theController.excludedActivityTypes = @[ UIActivityTypeAssignToContact,
    UIActivityTypeSaveToCameraRoll, UIActivityTypePostToFlickr,
    UIActivityTypePostToVimeo, UIActivityTypeAirDrop ];
[self presentViewController:theController animated:YES completion:NULL];

where self implements UIActivityItemSource.