如果安装在设备上的按钮点击上,我需要在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.")
}
}
如果您一定不使用FB / Twitter SDK。那么您可以尝试使用活动控制器并从您的应用中共享。在这里,您将获得所有可能的购股权。
var activityViewController:UIActivityViewController?
textField .text = "Some Test"
@IBAction func shareText(sender: UIButton) {
activityViewController = UIActivityViewController(
activityItems: [textField.text as NSString],
applicationActivities: nil)
presentViewController(activityViewController, animated: true, completion: nil)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句