Christopher Francisco
Christopher Francisco

Reputation: 16268

Calling the system share menu on iOS 8

I'm trying to figure out how to programatically show the system share menu, but all info I can find is how to register an app to said menu.

How can I call the dialog programatically?

Upvotes: 0

Views: 1596

Answers (1)

Fred Faust
Fred Faust

Reputation: 6790

You need to create an instance of UIActivityViewController, here's a quick example

let objectsToShare = ["a string"]
let activityController = UIActivityViewController(
        activityItems: objectsToShare,
        applicationActivities: nil)

    // if your app can run on an iPad, this menu
    // will present as a pop over controller
    // and as such, needs to be configured
    // consider the bar button item property
    // if needed

    // should be the rect that the pop over should anchor to
    activityController.popoverPresentationController?.sourceRect = view.frame
    activityController.popoverPresentationController?.sourceView = view
    activityController.popoverPresentationController?.permittedArrowDirections = .any

    // present the controller
    present(activityController, animated: true, completion: nil)

Upvotes: 4

Related Questions