Swift : 通过 Twitter 分享文本 [英] Swift : Share text through Twitter
本文介绍了Swift : 通过 Twitter 分享文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以基本上我正在制作一个事件应用程序.一切都很顺利,但只是将活动分享到 Twitter.
So basically I am making an event app. Everything has been going smoothly but there's just sharing the event to twitter.
我已经搜索了互联网,但我得到的只是使用我不想要的 twitter 的本机应用程序.我想用浏览器发推文.
I have searched the internet but all I am getting is using the native app of twitter which I don't want. I want to use the browser to tweet.
我已经为FB分享实现了这个方法.
I have implemented this method for FB sharing.
任何想法都会对我有很大帮助.
Any idea would help me a lot.
let content = FBSDKShareLinkContent()
content.contentURL=NSURL(string: "http://facebook.com")
content.imageURL = NSURL(string: "http://facebook.com")
content.contentTitle = "Shou 3emlin test app "
content.contentDescription = "testing testing testing"
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.mode=FBSDKShareDialogMode.Browser
shareDialog.shareContent = content
if !shareDialog.canShow() {
shareDialog.mode=FBSDKShareDialogMode.Native
shareDialog.shareContent = content
}
if shareDialog.canShow() {
shareDialog.show()
}
推荐答案
将其放入按钮的操作方法或您希望使用浏览器发送文本的方法中 Swift 3.0:
Put this in an action method of a button or in the method where you want to use the browser to tweet your text Swift 3.0:
let tweetText = "your text"
let tweetUrl = "http://stackoverflow.com/"
let shareString = "https://twitter.com/intent/tweet?text=\(tweetText)&url=\(tweetUrl)"
// encode a space to %20 for example
let escapedShareString = shareString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
// cast to an url
let url = URL(string: escapedShareString)
// open in safari
UIApplication.shared.openURL(url!)
结果:
这篇关于Swift : 通过 Twitter 分享文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文