如何在Swift中创建像Andoid这样的共享选项

时间:2018-10-29 05:29:43

标签: ios swift share

我需要显示一个选项以使用swift共享一些细节,例如Android 如何显示包含要共享的应用程序列表的屏幕 请查看以下屏幕截图。

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

private func shareWhatYouWant() {

    //pop invite view
    var textToShare = "Your message"
    if let myWebsite = NSURL(string: "Yourwebsite.com") {
        let objectsToShare = [textToShare, myWebsite] as [Any]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        //New Excluded Activities Code

        activityVC.completionWithItemsHandler = {
            activity, sucess, items, error in
            if !sucess {
                print("cancelled")
                return
            }
            if activity == UIActivityType.postToFacebook {
                print("share on facebook")
            }
            if activity == UIActivityType.postToTwitter {
                print("share on twitter")
            }
            if activity == UIActivityType.message {
                print("share on message")
            }
            if activity == UIActivityType.addToReadingList {
                print("air drop select")
            }
        }

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