2016-12-01 142 views
3

我成功安裝了Facebook pod(全部三種),並且我可以在我的應用中登錄用戶,但我無法共享任何內容。Facebook與Swift 3和Swift SDK共享(0.2.0)

代碼很簡單(它從樣本項目,而不是真實的):

import FacebookLogin 
import FacebookShare 

在viewDidLoad中():

button.addTarget(self, action: "sharePic", for: .touchUpInside) 

而且我也有:

func sharePic() { 

    let url = URL(fileURLWithPath: "https://developers.facebook.com")   
    let content = LinkShareContent(url: url, title: "facebook", description: "facebook developers", quote: "fbd", imageURL: nil) 
    try! ShareDialog.show(from: self, content: content) 
} 

在此我不斷收到此錯誤消息:

fatal error: 'try!' expression unexpectedly raised an error: FacebookShare.ShareError.reserved: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 178 

我對「嘗試!」沒有任何問題。 (我知道這是一個不好的做法),但我不明白我的代碼出了什麼問題,以及如何理解這裏出了什麼問題。

+0

你有什麼解決辦法嗎?即使我有同樣的問題 –

+0

不是真的,不。我正在使用iOS共享代替(它不那麼有光澤,但它的工作原理,並沒有視頻共享限制) – lithium

+0

我能夠解決這個問題。已發佈代碼作爲回答下面的 –

回答

3
func showShareDialog<C: ContentProtocol>(_ content: C, mode: ShareDialogMode = .automatic) { 
    let dialog = ShareDialog(content: content) 
    dialog.presentingViewController = self 
    dialog.mode = mode 

    do { 
     try dialog.show() 
    } catch (let error) { 
     Toast(text: "Invalid share content. Failed to present share dialog with error \(error)", duration: Delay.short).show() 
    } 
} 

func fbClick() { 
    var content = LinkShareContent(url: URL(string: "http://example.com")!, 
            title: "Title", 
            description: "Description", 
            imageURL: "http://test.com/test.png") 

    showShareDialog(self.content!, mode: .native) 
} 
+1

出現錯誤「保留」 – Xie

+0

我也收到錯誤消息保留 –

+0

有沒有人有這個答案?我有同樣的問題,我不斷收到錯誤「保留」 –