Greg Maletic
Greg Maletic

Reputation: 6337

Multiple UIActivityViewController placeholder items?

UIActivityItemSources, it seems, can only return one kind of placeholder item? This seems strange, because I have a UIActivityItemSource that could return a string, an NSData object, or an image depending upon the activity it's given.

Is there really no way to return more than one kind of placeholder? (NSArrays don't seem to work.)

(I could imagine a solution where I instantiate a bunch of UIActivityItemProvider instances, each supporting the different datatypes mentioned above. But that seems like a lot more work than should be necessary...?)

Upvotes: 4

Views: 2893

Answers (1)

sha
sha

Reputation: 17860

If you add a trace inside your itemForActivityType function you will see that this function will be called multiple times. One for each activity available for share.

For example - if I want to provide different text for Twitter and mail/sms sharing I would have something like this:

- (id) activityViewController: (UIActivityViewController*) activityViewController itemForActivityType: (NSString*) activityType {

    if (activityType == UIActivityTypePostToTwitter) {
        return @"Sharing by Twitter";
    }
    else
        return @"Other kind of sharing";

}

UPDATE:

If you want to provide different types of data to share (say text and images) - you need to wrote your placeholder function in a way so it returns two different kind of object when called multiple times.

- (id) activityViewControllerPlaceholderItem: (UIActivityViewController*) activityViewController {
    static int step = 0;

    if (step == 0) {
        step = 1;
        return @"text";
    }
    else if (step == 1) {
        step = 2;
        return [UIImage imageNamed: @"image"];
    }
}

Upvotes: 2

Related Questions