Reimond Hill
Reimond Hill

Reputation: 4760

UIActivityViewController for Facebook, Twitter and Instagram ONLY

I am trying to get a UIActivityViewController for presenting only the options for Facebook, Twitter and Instagram. So far I have done:

    let shareText = "Hello, world!"

    let image = UIImage(named: "TheImage")
    let activityViewController = UIActivityViewController(activityItems: [shareText,image], applicationActivities: nil)
    activityViewController.excludedActivityTypes = [UIActivityType.addToReadingList,
                                                    UIActivityType.airDrop,
                                                    UIActivityType.assignToContact,
                                                    UIActivityType.copyToPasteboard,
                                                    UIActivityType.mail,
                                                    UIActivityType.message,
                                                    UIActivityType.openInIBooks,
                                                    UIActivityType.print,
                                                    UIActivityType.saveToCameraRoll
                                                    ]
    present(activityViewController, animated: true, completion: {})

But the UIActivityViewController is still giving me unwanted options.

I also thought to get and approach with NSExtensionItem but I am not sure about it.

Thank you

Upvotes: 3

Views: 7162

Answers (3)

rickrvo
rickrvo

Reputation: 565

As of now (march 2019), Instagram share option will only appear if you set an image and only that image on the activityItems. If you add a TEXT or URL object there as well the Instagram option will not show up.

Twitter, on the otehr hand would accept a TEXT and an IMAGE, but if you pass an URL too it will not show up as an option as well

Upvotes: 1

PGDev
PGDev

Reputation: 24341

Apple provides support for some of the default UIActivityTypes that includes both Facebook and Twitter as required by you.

You can get a complete list of UIActivityTypes here: https://developer.apple.com/documentation/uikit/uiactivitytype

By default, all the UIActivityTypes appear in the UIActivityController. The activities you don't want to appear in the UIActivityController an be added in the exclude list, i.e

activityViewController.excludedActivityTypes = [.postToFlickr, .postToVimeo]

Also, whenever an App that includes a Share App Extension is installed on the device, it is also added to the UIActivityController.

Example:

WhatsApp. Whenever you install WhatsApp on your device, it will appear as a Share App Extension in the UIActivityController. You cannot remove them but can only hide them from the UIActivityController's More option.

Let me know if you still face any issues.

Upvotes: 1

Sagar Chauhan
Sagar Chauhan

Reputation: 5823

There are option available for Facebook and Twitter, You need to just add excludedActivityTypes. You have missing it.

Instagram option still not available in activity types

let image = UIImage(named: "TheImage")
let activityViewController = UIActivityViewController(activityItems: [shareText,image], applicationActivities: nil)

activityViewController.excludedActivityTypes = [.addToReadingList,
                                               .airDrop,
                                               .assignToContact,
                                               .copyToPasteboard,
                                               .mail,
                                               .message,
                                               .openInIBooks,
                                               .print,
                                               .saveToCameraRoll,
                                               .postToWeibo,
                                               .copyToPasteboard,
                                               .saveToCameraRoll,
                                               .postToFlickr,
                                               .postToVimeo,
                                               .postToTencentWeibo,
                                               .markupAsPDF
]    

present(activityViewController, animated: true, completion: {})

I hope this will help you.

There are following list of Activity types available.

extension UIActivityType {


    @available(iOS 6.0, *)
    public static let postToFacebook: UIActivityType

    @available(iOS 6.0, *)
    public static let postToTwitter: UIActivityType

    @available(iOS 6.0, *)
    public static let postToWeibo: UIActivityType // SinaWeibo

    @available(iOS 6.0, *)
    public static let message: UIActivityType

    @available(iOS 6.0, *)
    public static let mail: UIActivityType

    @available(iOS 6.0, *)
    public static let print: UIActivityType

    @available(iOS 6.0, *)
    public static let copyToPasteboard: UIActivityType

    @available(iOS 6.0, *)
    public static let assignToContact: UIActivityType

    @available(iOS 6.0, *)
    public static let saveToCameraRoll: UIActivityType

    @available(iOS 7.0, *)
    public static let addToReadingList: UIActivityType

    @available(iOS 7.0, *)
    public static let postToFlickr: UIActivityType

    @available(iOS 7.0, *)
    public static let postToVimeo: UIActivityType

    @available(iOS 7.0, *)
    public static let postToTencentWeibo: UIActivityType

    @available(iOS 7.0, *)
    public static let airDrop: UIActivityType

    @available(iOS 9.0, *)
    public static let openInIBooks: UIActivityType

    @available(iOS 11.0, *)
    public static let markupAsPDF: UIActivityType
}

Upvotes: 3

Related Questions