我需要在设备上点击按钮时,在Facebook和Twitter应用程序中分享一些链接。 我可以使用WhatsApp共享相同的内容(代码如下)。 我想知道是否也可以在Facebook和Twitter应用程序中进行相同的操作。
@IBAction func whatsappbtn(_ sender: UIButton) {
var str = "This is the string which you want to share to WhatsApp"
str=str.addingPercentEncoding(withAllowedCharacters: (NSCharacterSet.urlQueryAllowed))!
let whatsappURL = URL(string: "whatsapp://send?text=\(str)")
if UIApplication.shared.canOpenURL(whatsappURL!) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(whatsappURL!, options: [:], completionHandler: nil)
} else {
// Fallback on earlier versions
}
} else {
self.delegate?.alerting(msg: "Please install Whatsapp and try again.")
}
}