FBSDKShareDialog cancels when it should post

后端 未结 4 1822
南笙
南笙 2021-01-01 22:00

I create a FBSDKShareDialog in code

- (void)shareWithFacebookDialog;
{  
  FBSDKShareLinkContent* content = [[FBSDKShareLinkContent alloc] init];
  content.c         


        
相关标签:
4条回答
  • 2021-01-01 22:42

    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];
    }
    
    0 讨论(0)
  • 2021-01-01 22:45

    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)
    
    0 讨论(0)
  • 2021-01-01 22:56

    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.

    0 讨论(0)
  • 2021-01-01 23:03

    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]
      }
    
    0 讨论(0)
提交回复
热议问题