2015-05-16 23 views
4

我有FBSDK共享功能用下面的代碼工作:使用Swift將UIImage直接添加到FBSDKShareLinkContent中?

if (FBSDKAccessToken.currentAccessToken() != nil) { 
     // User is already logged in, do work such as go to 

     let content : FBSDKShareLinkContent = FBSDKShareLinkContent() 
     content.contentURL = NSURL(string: self.url_string) 
     content.contentTitle = self.title_text 
     content.contentDescription = self.desc_text 
     content.imageURL = NSURL(string: "http://image.png") 

     let button : FBSDKShareButton = FBSDKShareButton() 
     button.shareContent = content 
     button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30) 
     button.center = self.view.center 
     self.view.addSubview(button) 

    } 

的問題是,我沒有一個IMAGEURL,我直接從存儲爲一個UIImage變量應用的相機功能拍攝的圖像。如何在沒有在線託管圖像的情況下將圖像附加到此FBSDKShareLinkContent?我使用的是FBSDKShareLinkContent,因爲我還分享了鏈接w /標題&說明。

編輯我試圖用FBSDKSharePhoto(正如某人所建議的)使用此代碼發佈照片,但即使content.contentURL被定義爲之前的版本,我仍無法正確鏈接該網址。

let photo : FBSDKSharePhoto = FBSDKSharePhoto() 
     photo.image = self.scaledImage 
     photo.userGenerated = true 

     let content : FBSDKSharePhotoContent = FBSDKSharePhotoContent() 
     content.contentURL = NSURL(string: self.url_string) 
     content.photos = [photo] 

     let button : FBSDKShareButton = FBSDKShareButton() 
     button.shareContent = content 
     button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30) 
     button.center = CGPointMake(self.view.center.x, self.descLabel.center.y + 51 + 30) // 51 = 1/2 of height of descLabel, 30 = space below 
     self.view.addSubview(button) 
+0

對於本地照片共享,您可以使用'FBSDKSharePhotoContent'。鏈接共享實際上共享一個鏈接(在線內容),並附加到它的imageUrl屬性是它的參考圖像。我也想做你所要求的東西,但找不到任何東西... – Pushparaj

+0

事情是我想分享一個標題和描述旁邊的圖像鏈接。我不認爲我可以這樣做FBSDKSharePhotoContent – Andrew

+0

如果我使用FBSDKSharePhotoContent我可以讓圖像發佈,但我怎麼得到那裏的鏈接? – Andrew

回答

1

看來FBSDKSharePhotoContent是要走的路,但目前一個錯誤,Facebook是知道的,這是造成圖像&鏈接無法一起工作。

https://developers.facebook.com/bugs/949486035103197/

他們說,這應該在未來的Facebook應用程序更新V31進行更新。 v30已於5月7日更新,FB每兩週發佈更新一次,因此我會在一週內再次檢查並確認功能已修復。

+0

是固定的嗎?即使我有相同的要求? – DanMatlin

相關問題