Return text, url and image to UIActivityItemProvider

I am subclassing the UIActivityItemProvider for my UIActivityViewController so that when the user selects UIActivityTypeMessage it will only show the message, but if the user selects UIActivityTypeFacebook it will show the message with the image.

This is my code and I can only return a message with UIActivityTypeMessage, but for UIActivityTypeFacebook, I don't know how to return a message with an image.

- (id)item
{
    if ([self.placeholderItem isKindOfClass:[NSString class]]) {
        if ([self.activityType isEqualToString:UIActivityTypeMessage]) {
            return [NSString stringWithFormat:@"%@\n%@",self.text,self.url];
        } else {
            NSDictionary *d = [[NSDictionary alloc] initWithObjects:@[self.text,self.image] forKeys:@[@"text",@"image"]];
            return d;
        }
    }
    return self.placeholderItem;
}

      

Are there special keys and values ​​for the UIActivityItemProvider that I can use to set the message, url and image?

As an update, I read in the UIActivity class reference that there are constants for a specific type of activity. Don't know how to use them. Can someone enlighten me please?

* UIActivityTypePostToFacebook Object posts provided content to users on Facebook.

When using this service, you can provide NSString, NSAttributedString, UIImage, ALAsset, and NSURL as data for the activity items. You can also specify NSURL objects whose content uses library asset schemas.

+3


source to share


1 answer


You will need to create 3 separate activity providers, one for each data type, and pass them all to functions initWithActivityItems:applicationActivities:

on UIActivityViewController

. The actions use all the providers you provide, and UIActivityViewController

hide any that don't support ALL of them (which can make it difficult to include only the image in some cases, for example).



+3


source







All Articles