我尝试使用UIActivityView为我的应用创建共享按钮。当我按下应用程序中的按钮时出现错误。代码有什么问题?
@IBAction func shareButton(_ sender: UIButton) {
let texttoshare = "Sharing"
let URLtoshare = NSURL(string: "www.google.com")
let objectsToShare:NSArray = [texttoshare, URLtoshare!]
let activityVC = UIActivityViewController(activityItems: objectsToShare as! [Any], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)
}
}
错误:是线程1:信号SIGABRT
答案 0 :(得分:0)
试试这个。至少,它没有错误地为我工作..
let texttoshare = "Sharing"
let URLtoshare = URL(string: "www.google.com")
let activityVC = UIActivityViewController(activityItems: [texttoshare, URLtoshare!], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)
如果您想将UIActivityViewController
用于iPad,则需要为popoverPresentationController?.sourceView
指定activityVC
。例如:
let texttoshare = "Sharing"
let URLtoshare = URL(string: "www.google.com")
let activityVC = UIActivityViewController(activityItems: [texttoshare, URLtoshare!], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = button...
self.present(activityVC, animated: true, completion: nil)