我在代码
中创建了一个FBSDKShareDialog- (void)shareWithFacebookDialog;
{
FBSDKShareLinkContent* content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"Path Redacted"];
content.contentTitle = @"Title Redacted";
content.contentDescription = @"Description Redacted";
FBSDKShareDialog* dialog = [[FBSDKShareDialog alloc] init];
[dialog setMode:FBSDKShareDialogModeNative];
[dialog setShareContent:content];
[dialog setDelegate:self];
[dialog setFromViewController:self];
[dialog show];
}
对话框启动,所有信息都正确
但是只要点击Post,对话框就会关闭,并且会调用取消委托。
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer;
有没有人见过这个?找到了克服它的方法吗?
答案 0 :(得分:9)
用这个
替换你的代码- (void)shareWithFacebookDialog;
{
FBSDKShareLinkContent content = [[FBSDKShareLinkContent alloc]init];
content.contentURL = [NSURL URLWithString:@"https://www.google.com"];
content.contentTitle = @"ContentTitle";
content.contentDescription = @"ContentDescription";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];
}
告诉我它是否有效。
答案 1 :(得分:0)
当我尝试在登录后立即调用该方法时,发生了这种情况。
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error || result.isCancelled) {
} else {
[self shareWithFacebookDialog];
}
}];
如果我在没有登录的情况下调用它(它应该已经有有效的令牌),它就可以工作。
if ([FBSDKAccessToken currentAccessToken]) {
[self shareWithFacebookDialog];
}
答案 2 :(得分:0)
I had the same problem: Facebook SDK share always returns sharerDidCancel
My error was in the AppDelegate method:
here is a link with the solution http://jitu1990.blogspot.it/2015/05/share-with-facebook-from-ios-app.html
And here is the code
- (BOOL)application:(UIApplication *)application openURL:(NSURL* )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url sourceApplication:sourceApplication annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [ [FBSDKApplicationDelegate sharedInstance] application :application
didFinishLaunchingWithOptions:launchOptions]
}
答案 3 :(得分:0)
对于Facebook SDK v4.5 +,请尝试以下方法:
目标-C
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"http://developers.facebook.com"];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
夫特
let content = FBSDKShareLinkContent()
content.contentURL = URL(string: "http://developers.facebook.com")
FBSDKShareDialog.show(from: self, with: content, delegate: self)