2

As discussed here & here, it's possible to exclude other ActivityType options using UIActivityViewController's excludedActivityTypes, beyond just those which are pre-defined.

However, how does one find out the identifiers for any given ActivityType (ideally programmatically at build-/run-time, if possible), so they can then be excluded?

For example, I'm looking to disable Send to Kindle and Chrome.

TheNeil
  • 3,321
  • 2
  • 27
  • 52

2 Answers2

0

To find out the ActivityType of a third party activity, select that activity after displaying your UIActivityViewController.

When the completion handler is called, completion closure/block you provided to the activity controller has a parameter with a type of ActivityType telling you which one was chosen.

For example:

activityVC.completionWithItemsHandler = { activity, success, items, error in
    print("activity: \(activity), success: \(success), items: \(items), error: \(error)")
}

Now you know the ActivityType for that activity. Update your code to add that value to the list you pass to excludedActivityTypes.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thanks! It took me a while to work out exactly how to do this, so I've edited your answer with some example code. I'm also going to edit the question so it's more focused on getting the identifier for any activity. Hopefully you'll get more votes that way. – TheNeil May 17 '19 at 19:59
  • Unfortunately, even though I got the exact identifiers from this method, they still aren't being excluded. Any idea why this wouldn't be working? ```let kindleActivity = UIActivity.ActivityType(rawValue: "com.amazon.Lassen.SendToKindleExtension"); let chromeActivity = UIActivity.ActivityType(rawValue: "com.google.chrome.ios.ShareExtension"); activityVC.excludedActivityTypes = [kindleActivity, chromeActivity]``` – TheNeil May 17 '19 at 20:16
  • 1
    Unfortunately it seems that UIActivityViewController does not honor every activity type you try to exclude. I've run into this in the past and I'm sure I've similar similar questions posted. It's almost as if you can only exclude activities that have a constant listed for ActivityType. – rmaddy May 17 '19 at 20:30
  • That's a real shame. It doesn't appear to be all without a constant, because I did manage to exclude `UIActivity.ActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension")` and `UIActivity.ActivityType(rawValue: "com.apple.mobilenotes.SharingExtension")`, which don't seem to have their own, but they are also iOS-native activities, so this might be why they worked. – TheNeil May 17 '19 at 20:31
0

FYI, as determined by @rmaddy's excellent answer, these are the specific identifiers for Send to Kindle and Chrome, if anyone's interested:

let kindleActivity = UIActivity.ActivityType(rawValue: "com.amazon.Lassen.SendToKindleExtension")
let chromeActivity = UIActivity.ActivityType(rawValue: "com.google.chrome.ios.ShareExtension")

There are many other examples already defined in this answer to a related question.

Unfortunately, even when these are added to the array for excludedActivityTypes, they still seem to show up in the UIActivityViewController. Any input on why, and how this can be fixed, is very welcome!

TheNeil
  • 3,321
  • 2
  • 27
  • 52