2017-03-28 68 views
2

共享對話框打開Facebook應用程序,儘管內容已成功共享,我總是收到。取消回撥。在這兩種情況下 - 當我取消共享和共享成功時。任何想法有什麼不對? 莢版本:Facebook ShareDialog總是返回。完成時取消

Using Bolts (1.8.4) 
Using FBSDKCoreKit (4.20.2) 
Using FBSDKLoginKit (4.20.2) 
Using FBSDKShareKit (4.20.2) 
Using FacebookCore (0.2.0) 
Using FacebookLogin (0.2.0) 
Using FacebookShare (0.2.0) 

代碼段用於顯示對話框:

@IBAction func onShareClicked(_ sender: UIButton) { 
    do{ 
     var myContent = LinkShareContent(url: URL(string: "https://www.facebook.com/8MinuteWorkoutChallenge")!) 
     myContent.hashtag = Hashtag("#8MWC") 

     let shareDialog = ShareDialog(content: myContent) 
     shareDialog.mode = .native 
     shareDialog.failsOnInvalidData = true 
     shareDialog.completion = { result in 
      switch result { 
      case .success: 
       print("Share succeeded") 
      case .failed: 
       self.shareButton.isHidden = true 
      case .cancelled: 
       print("Share cancelled") 
      } 
     } 

     try shareDialog.show() 
    } catch { 
     print("Error: \(error)") 
    } 
} 

配置

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>fbapi</string> 
    <string>fb-messenger-api</string> 
    <string>fbauth2</string> 
    <string>fbshareextension</string> 
</array> 
<key>CFBundleURLTypes</key> 
<array> 
    <dict> 
     <key>CFBundleURLSchemes</key> 
     <array> 
      <string>fb188***33776</string> 
     </array> 
    </dict> 
</array> 
<key>FacebookAppID</key> 
<string>18851***3776</string> 
<key>FacebookDisplayName</key> 
<string>8MWC</string> 
+0

您是否要求用戶的發佈許可? –

+0

不,我沒有。在文檔和分享工作中沒有任何關於此的內容,但不是回調。 –

回答

1

使用此下面的代碼來顯示FB份額對話框當前視圖控制器:

{ 
    let shareDialog: FBSDKShareDialog = FBSDKShareDialog() 
    shareDialog.shareContent = content 
    shareDialog.delegate = self 
    shareDialog.fromViewController = self 
    shareDialog.show() 
} 

這適用於我分享鏈接到Facebook。您可以使用委託方法獲取份額狀態回調。

+0

這是爲老sdk。新的有不同的api –

+0

shareDialog.presentingViewController =自己做的伎倆。謝謝 –

1

首先,檢查是否授予publish action的許可,如果是的話,那麼share您的content。 否則,獲得用戶的許可,在其時間軸上發佈帖子,然後在授予權限後共享帖子。

if FBSDKAccessToken.current().hasGranted("publish_actions") { 
     if FBSDKShareAPI().self.canShare() { 
      FBSDKShareAPI.share(with: videoContent, delegate: self) 
     } else { 
      print("Graph API can not share your video") 
     } 

    } else { 

     // Get publish_actions permission from fb app and upload photo to share. 
     let loginManager = FBSDKLoginManager() 
     loginManager.logIn(withPublishPermissions: ["publish_actions"], from: fromViewController, handler: { (result, error) in 

      if result != nil && error == nil { 

       if FBSDKShareAPI().self.canShare() { 
        FBSDKShareAPI.share(with: videoContent, delegate: self) 
       } else { 
        print("Graph API can not share your video") 
       } 
      } else if error != nil { 
       print("Error in sharing photo:- \(error!)") 
      } 
     }) 
    }