iOS 10 中的 UIActivityViewController

UIActivityViewController in iOS 10

有人知道如何在 iOS 10 中使用 UIActivityView 吗?现在由于某种原因在 Swift 3.0 中它会编译和构建但是当应用程序是 运行 按下共享按钮后使用以下代码导致应用程序崩溃......它在 iOS 9.3 和 Swift 2.0.

如代码第 6 行的注释中所述或 let objectsToShare = [textToShare] as! AnyObject 导致线程 1:信号 SIGABRT 和应用程序崩溃

@IBOutlet weak var detailDescriptionLabel: UITextView!

@IBAction func share(_ sender: AnyObject) {
        let textToShare = detailDescriptionLabel.attributedText

        let objectsToShare = [textToShare] as! AnyObject
        // line above causes app crash in iOS 10 - compiled and built
        // error is "Thread1: signal SIGABRT"

        let activityVC = UIActivityViewController(activityItems: objectsToShare as! [AnyObject], applicationActivities: nil)

        activityVC.popoverPresentationController?.sourceView = (sender as! UIView)
        self.present(activityVC, animated: true, completion: nil)
    }


class ActivityForNotesViewController: UIActivityViewController {

    internal func _shouldExcludeActivityType(_ activity: UIActivity) -> Bool {
        let activityTypesToExclude = [
            //insert UIActivity here
        ]

        if let actType = activity.activityType {
            if activityTypesToExclude.contains(actType) {
                return true
            }
            else if super.excludedActivityTypes != nil {
                return super.excludedActivityTypes!.contains(actType)
            }
        }
        return false
    }
}

如果有人能帮助我,我将不胜感激。

我想我可能已经回答了我自己的问题,但如果有人能仔细检查,我将不胜感激。代码中的注释是我为使此修复生效所做的各种更改。在模拟器和真实设备中 iOS 10 中工作。

@IBAction func share(_ sender: AnyObject) {
        // Changed attributedText to text!
        let textToShare = detailDescriptionLabel.text!

        // Removed Cast to AnyObject
        let objectsToShare = [textToShare]

        //Removed cast to AnyObject in the Function Call to get rid of error from removing it above
        let activityVC = UIActivityViewController(activityItems: objectsToShare , applicationActivities: nil)


//Moved cast for as! UIView outside the perantheses of sender so 
//that the as! can be used more efficiently. But most importantly
// I changed the as! to a as? instead thinking that might catch an error and it did... so this works.

        activityVC.popoverPresentationController?.sourceView = (sender) as? UIView
                self.present(activityVC, animated: true, completion: nil)
}
let objectsToShare = [textToShare]

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

应该是这样使用的