TJActivityViewController
Simple customization for the iOS share sheet.
Install / Use
/learn @timonus/TJActivityViewControllerREADME
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!
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
