I create a FBSDKShareDialog in code
- (void)shareWithFacebookDialog;
{
FBSDKShareLinkContent* content = [[FBSDKShareLinkContent alloc] init];
content.c
This happened to me when I tried to call the method right after login.
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error || result.isCancelled) {
} else {
[self shareWithFacebookDialog];
}
}];
It works if I just call it without logging in (should already have valid token).
if ([FBSDKAccessToken currentAccessToken]) {
[self shareWithFacebookDialog];
}
For Facebook SDK v4.5+, try this:
Objective-C
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"http://developers.facebook.com"];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
Swift
let content = FBSDKShareLinkContent()
content.contentURL = URL(string: "http://developers.facebook.com")
FBSDKShareDialog.show(from: self, with: content, delegate: self)
replace your code with this
- (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];
}
tell me if it works.
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]
}