tja

TJActivityViewController

Simple customization for the iOS share sheet.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

49

Maintenance

Last Commit

1mo ago

Contributors

4

Package

Dependencies

0

License

BSD 3-Clause License

Categories

Readme

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!

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100