2

I'm using the following code to share a string only to Facebook using UIActivityViewController

UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
                                applicationActivities:nil];

activityViewController.excludedActivityTypes = @[UIActivityTypePostToWeibo,
                                   UIActivityTypeMessage,
                                   UIActivityTypeMail,
                                   UIActivityTypePrint,
                                   UIActivityTypeCopyToPasteboard,
                                   UIActivityTypeAssignToContact,
                                   UIActivityTypeSaveToCameraRoll,
                                   UIActivityTypeAddToReadingList,
                                   UIActivityTypePostToFlickr,
                                   UIActivityTypePostToVimeo,
                                   UIActivityTypePostToTencentWeibo,
                                   UIActivityTypeAirDrop,
                                   UIActivityTypePostToTwitter];


[self presentViewController:activityViewController animated:YES completion:^{
...
}

This works except it also shows the WhatsApp icon and the more icon. Is there a way to remove these two? Thanks in advance!

MVZ
  • 2,220
  • 5
  • 27
  • 57
  • it can only be removed by user, not by developers.As its share extension provided by Whatsapp – Mukesh Oct 08 '15 at 03:28

2 Answers2

7

Whilst rmaddy's answer used to be true, for anyone coming across this since iOS 10 it's fairly simple to do:

activityController.excludedActivityTypes = [
    UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension")
]

If you want to hide other non-system activity types, you can share to them, and then use the identifier returned in the completionWithItemsHandler closure:

shareActivityController.completionWithItemsHandler = { [weak self] (activityType, completed, returnedItems, activityError) in
    print("Activity Type", activityType?.rawValue ?? "?") // <--- Use the identifier this logs!
}

Although admittedly in the case of the OP's question, this still isn't going to help you as to limit it to only Facebook, you'd have to install all the other thousands of apps with share activities in order to disable them all!

Here are all the identifiers for apps I happened to have installed on my iPhone:

UIActivity.ActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension"),
UIActivity.ActivityType(rawValue: "com.apple.mobilenotes.SharingExtension"),
UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"),
UIActivity.ActivityType(rawValue: "pinterest.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.facebook.Messenger.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.tinyspeck.chatlyio.share"), // Slack!
UIActivity.ActivityType(rawValue: "ph.telegra.Telegraph.Share"),
UIActivity.ActivityType(rawValue: "com.google.Drive.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.toyopagroup.picaboo.share"), // Snapchat!
UIActivity.ActivityType(rawValue: "wefwef.YammerShare"),
UIActivity.ActivityType(rawValue: "com.fogcreek.trello.trelloshare"),
UIActivity.ActivityType(rawValue: "com.linkedin.LinkedIn.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.hammerandchisel.discord.Share"),
UIActivity.ActivityType(rawValue: "com.google.Gmail.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.google.inbox.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.riffsy.RiffsyKeyboard.RiffsyShareExtension"), //GIF Keyboard by Tenor
UIActivity.ActivityType(rawValue: "com.google.hangouts.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share")
simonthumper
  • 1,834
  • 2
  • 22
  • 44
  • Here are a couple more for **Send to Kindle** & **Chrome**: ```let kindleActivity = UIActivity.ActivityType(rawValue: "com.amazon.Lassen.SendToKindleExtension") let chromeActivity = UIActivity.ActivityType(rawValue: "com.google.chrome.ios.ShareExtension")``` ...however, even when these are added to the exclusion array, the `UIActivityViewController` still shows them. Any idea why!? – TheNeil May 17 '19 at 20:36
  • @TheNeil I have no idea I'm afraid! – simonthumper May 20 '19 at 13:01
  • 4
    Here's a longer list. https://gist.github.com/robksawyer/544efe1c4dc7e4ce2fb9d3b589dde5a0 – Rob Sawyer Sep 28 '20 at 15:28
  • This does not seem to work any longer. At least with Xcode 13 and iOS 14 – letsbondiway Jul 14 '22 at 14:14
  • Interesting @letsbondiway, as in it doesn't block ANY activities? Or have those identifiers perhaps changed? – simonthumper Jul 20 '22 at 08:06
5

No, you can only remove activity types that Apple has provided constants for. There is no way to remove 3rd party apps that appear or the "More..." activity.

If you only want to share with a single, specific app, there's no point in using a UIActivityController.

Use one of the various Facebook libraries/APIs to share your data with Facebook.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Also "More..." button lets the user reorder the icons so you can't remove that in anyway. – Imran Oct 08 '15 at 01:58