UIActivityViewController on iPad

Tom Coomer picture Tom Coomer · Oct 1, 2015 · Viewed 10.7k times · Source

I have been using the code below to show a UIActivityViewController which worked fine when I was using Xcode 6, Swift 1.2 and iOS 8. However when I updated it shows the UIActivityViewController but it is completely blank without any of the sharing options. Do you have any suggestions?

if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
        let textToShare = textViewOne.text

            let objectsToShare = [textToShare]
            let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

            let nav = UINavigationController(rootViewController: activityVC)
            nav.modalPresentationStyle = UIModalPresentationStyle.Popover
            let popover = nav.popoverPresentationController as UIPopoverPresentationController!

            popover.sourceView = self.view
            popover.sourceRect = sender.frame

            self.presentViewController(nav, animated: true, completion: nil)

    } else {
        let textToShare = textViewOne.text

        let objectsToShare = [textToShare]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

        self.presentViewController(activityVC, animated: true, completion: nil)

    }

Answer

Tom Coomer picture Tom Coomer · Oct 3, 2015

This has fixed it.

        let objectsToShare = [textToShare]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        activityVC.title = "Share One"
        activityVC.excludedActivityTypes = []

        activityVC.popoverPresentationController?.sourceView = self.view
        activityVC.popoverPresentationController?.sourceRect = sender.frame

        self.presentViewController(activityVC, animated: true, completion: nil)

in swift 3.0:

let objectsToShare = [textToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.title = "Share One"
activityVC.excludedActivityTypes = []

activityVC.popoverPresentationController?.sourceView = self.view
activityVC.popoverPresentationController?.sourceRect = sender.frame

self.present(activityVC, animated: true, completion: nil)