Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 2.95 KB

README.md

File metadata and controls

53 lines (37 loc) · 2.95 KB

TJActivityViewController

TJActivityViewController is a handy subclass of UIActivityViewController that allows you to override actions easily without implementing UIActivityItemSource.

Usage

You can override a particular activity or one matching a regex with a block using the following methods:

UIImage *imageToShare = /* ... */;
TJActivityViewController *viewController = [[TJActivityViewController alloc] initWithActivityItems:@[imageToShare] applicationActivities:nil];

// Override Twitter sharing with a block.
[viewController overrideActivityType:UIActivityTypePostToTwitter withBlock:^{
    // Launch a custom Twitter share action.
}];

// Override actions matching a regex.
[viewController overrideActivityTypeMatchingRegex:@"com\\.foo\\.bar\\..*" withBlock:^{
    // Custom sharing actions.
}];

You can also override the item that's passed to a particular activity with a block using the following method:

// TJActivityViewControllerSnapchatActivityType and a few others are provided for convenience
[viewController overrideItemForActivityType:TJActivityViewControllerSnapchatActivityType // Snapchat's share extension	
                                  withBlock:^id {
	return /* a 9:16 image cropped just for Snapchat. */;
}];

In iOS 13 and above, you can set the link preview on an instance of TJActivityViewController using the linkMetadata property.

LPLinkMetadata *linkMetadata = [LPLinkMetadata new];
linkMetadata.title = @"My Cool Link";
linkMetadata.imageProvider = /* an image provider for your link preview */;
activityViewController.linkMetadata = linkMetadata;

Why

While UIActivityItemSource is a powerful API for sharing through UIActivityViewController, it's a bit cumbersome to use and has limitations when it comes to overriding actions. Many products now have custom sharing SDKs that are more powerful than their built-in share extensions, but developers who use UIActivityViewController are forced into using the less powerful share extensions.

Some developers have taken to building their own bespoke sharing menus to work around this limitation of UIActivityViewController, but that leads to fragmented and incomplete sharing experiences across products. TJActivityViewController gives you the best of both worlds: you get to use the standard iOS share menu, and can still customize sharing options with your own special touches.

For a more detailed blog post on the subject, see here.

About

I originally wrote TJActivityViewController for Close-up and have since also used it in Burst. If you decide to use TJActivityViewController let me know!