Excluding activity types for UIActivityViewController: some are still present

I try to exclude some activities from UIActivity.

It works as expected when exclusion is done directly with the activity, as with:

UIActivity.ActivityType.message,
UIActivity.ActivityType.airDrop

but not when activity is declared with an init as with:

UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share"),

So, with the following code:

        let excludedActivityTypes = [
                    UIActivity.ActivityType.message,
                    UIActivity.ActivityType.airDrop,
                    UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"),
                    UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share")
                ]
        let activityVC = UIActivityViewController(activityItems: [modifiedPdfURL], applicationActivities: nil) 
        activityVC.excludedActivityTypes = excludedActivityTypes

message and airDrop do not show, but WhatsApp and IFTTT still show.

I have tested with

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

that WhatsApp and IFTTT services are effectively the ones listed here.

When selecting WhatsApp, print above gives:

activity: Optional(__C.UIActivityType(_rawValue: net.whatsapp.WhatsApp.ShareExtension)), success: false, items: nil, error: nil

Accepted Reply

Apps can only exclude the built-in system activity types (the constants listed in the UIActivity.ActivityType struct), and are not allowed to exclude extension activities that come from other apps.

  • Thanks for the answer. It would be useful to have this mentioned in documentation.

Add a Comment

Replies

Apps can only exclude the built-in system activity types (the constants listed in the UIActivity.ActivityType struct), and are not allowed to exclude extension activities that come from other apps.

  • Thanks for the answer. It would be useful to have this mentioned in documentation.

Add a Comment

Except that's not 100% accurate. That is the behavior in iOS. However, you can exclude 3rd party extension activities when you build for macOS (built for iPad) or Catalyst.

I am excluding .postToWeibo but still I can see Weibo in the options. My code is

var activityViewController = UIActivityViewController(activityItems: [documentId+".pdf", pDfdata], applicationActivities: nil)   

activityViewController.excludedActivityTypes = [.postToTwitter, .postToFacebook, .postToFlickr, .postToTencentWeibo, .postToVimeo, .postToWeibo]

present(activityViewController, animated: true)

Can you please let me know what is the reason for this?

  • I think it was possible when Weibo was integrated in iOS (like Twitter and Facebook) but since those integrations have been removed from iOS and are now managed through Share Extension I think the accepted answer is the answer to your question.

Add a Comment

@DivuaACN read the correct answer ; Apps can only exclude the built-in system activity types (the constants listed in the UIActivity.ActivityType struct), and are not allowed to exclude extension activities that come from other apps.

  • @Claude31 I am using built in system activity types .postToWeibo. but still I can see Weibo in the shared apps options.

Add a Comment