[英]Facebook SDK for iOS: FBSDKShareDialog is not shown
我是iOS的新手,我想使用iOS版Facebook SDK共享鏈接。 我的代碼如下:
@IBAction func shareVoucherUsingFacebook(sender: UIButton) {
print("Facebook")
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "www.google.com")
content.contentTitle = "Content Title"
content.contentDescription = "This is the description"
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.delegate = self
shareDialog.fromViewController = self
shareDialog.show()
}
我還實現了FBSDKSharingDelegate
方法,但是當我按下此按鈕時,我無法接收到共享對話框,並且正在執行方法func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!)
,這意味着有事情要發生了。錯了,但我不知道。
提前致謝。
改變這條線
content.contentURL = NSURL(string: "www.google.com")
成
content.contentURL = NSURL(string: "https:\\www.google.com")
和我一起工作
這是我使用的委托方法
func sharer(sharer: FBSDKSharing!, didCompleteWithResults results: [NSObject: AnyObject])
{
print(results)
}
func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!)
{
print("sharer NSError")
print(error.description)
}
func sharerDidCancel(sharer: FBSDKSharing!)
{
print("sharerDidCancel")
}
如果您在代碼中使用NSURL(string:"")
,只需記住將http://
添加到contentURL
。
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://www.google.com")
content.contentTitle = "Content Title"
content.contentDescription = "This is the description"
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)
實現委托方法對我有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.