分享对话框打开Facebook应用程序,尽管内容已成功共享,但我始终收到 .cancelled 回调。在这两种情况下 - 当我取消共享和共享成功时。知道什么是错的吗? Pods版本:
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 :(得分:2)
使用以下代码显示当前View控制器的FB共享对话框:
{
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.delegate = self
shareDialog.fromViewController = self
shareDialog.show()
}
这对我来说可以分享到facebook的链接。您可以使用委托方法来获取共享状态回调。
答案 1 :(得分: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!)")
}
})
}
。
否则,获得用户的许可,以便在其时间轴上发布帖子,然后在获得许可的情况下分享帖子。
{
path: 'projects/learningconsole',
component: LearningConsoleComponent,
children: [
{ path: 'createdocument', component: CreateDocumentComponent, outlet: 'r1' },
{ path: 'createform', component: CreateFormComponent, outlet: 'r1' },
{ path: 'editform', component: EditFormComponent, outlet: 'r1' },
{ path: 'createcontrol', component: CreateControlComponent, outlet: 'r1' }
]
}