Here is an example of UIActivityItemProvider (not tested, but adapted from working code):
@implementation StringProvider - (id)initWithPlaceholderString:(NSString*)placeholder facebookString:(NSString*)facebookString { self = [super initWithPlaceholderItem:placeholder]; if (self) { _facebookString = facebookString; } return self; } - (id)item { if ([self.activityType isEqualToString:UIActivityTypePostToFacebook]) { return _facebookString; } else { return self.placeholderItem; } } @end
Then, when you configure the activity controller:
StringProvider *stringProvider = [[StringProvider alloc] initWithPlaceholderString:@"Default string" facebookString:@"Hello, Facebook."]; UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:@[stringProvider] applicationActivities:nil];
Basically, you create UIActivityItemProviders that provide the necessary data when the element method (id) is called and passed to these activity element providers when creating the activity type controller. You need to initialize the placeholder so that the OS knows which class will be the last (most likely, NSString, NSURL, UIImage). Hope this helps!
source share