0

我想在 FBLinkShareParams 上发布名称、链接描述和图片,但我无法在 Facebook 应用程序安装条件下执行此操作,但在FBWebDialogs中完成时,它在 Facebook 应用程序未安装条件下工作正常。我 只能在Facebook 应用安装条件下发布params.link 。

我使用了如下所示的代码:

      #pragma mark - facebook share
    //facebook share
    - (void)shareLinkinFB{
    /* Facebook app is installed*/
        FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
        params.link = [NSURL URLWithString:@"https://developers.facebook.com/docs/ios/share/"];
        params.name= @"Dieheart";
        params.picture= [NSURL URLWithString:Str_KoolkatPic];
        params.linkDescription=@"A quick and better way to get anything delivered at your doorstep. ";



        // If the Facebook app is installed and we can present the share dialog
        if ([FBDialogs canPresentShareDialogWithParams:params]) {
            [FBDialogs presentShareDialogWithLink:params.link handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {    if(error) {
                // An error occurred, we need to handle the error
                NSLog(@"Error publishing story: %@", error.description);
            } else {
                // Success
                NSLog(@"result %@", results);
            }
            }];
            NSLog(@"Share login page Now");


        } else {
            /* Facebook app Not installed*/
            NSLog(@"Share dialog");
            NSString *urlString = [NSString stringWithFormat:@"%@/resources/images/login-logo.png",SERVER_ADDRESS];
            NSString *Str_NameLabel;
            NSString *Str_Description;
            Str_NameLabel=@"testing for idelivery IOS application";
            Str_Description=@"Share functionality in progress";

            NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           Str_NameLabel, @"name",
                                           @"idelivery Town center", @"caption",
                                           Str_Description, @"description",
                                           @"https://www.facebook.com/edeliveryksa", @"link",
                                           urlString, @"picture",
                                           nil];
            // Show the feed dialog
            [FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params
                                                      handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                          if (error) {
                                                              // An error occurred, we need to handle the error
                                                              // See: https://developers.facebook.com/docs/ios/errors
                                                              NSLog(@"Error publishing story: %@", error.description);
                                                          } else {
                                                              if (result == FBWebDialogResultDialogNotCompleted) {
                                                                  // User cancelled.
                                                                  NSLog(@"User cancelled.");
                                                              } else {
                                                                  // Handle the publish feed callback
                                                                  NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

                                                                  if (![urlParams valueForKey:@"post_id"]) {
                                                                      // User cancelled.
                                                                      NSLog(@"User cancelled.");

                                                                  } else {
                                                                      // User clicked the Share button
                                                                      NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                                      NSLog(@"result %@", result);
                                                                      [self postSuccess]; // success vako condn ko lagi banako
                                                                  }
                                                              }
                                                          }
                                                      }];
        }}



    - (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication
             annotation:(id)annotation {

        BOOL urlWasHandled = [FBAppCall handleOpenURL:url
                                    sourceApplication:sourceApplication
                                      fallbackHandler:^(FBAppCall *call) {
                                          NSLog(@"Unhandled deep link: %@", url);
                                          // Here goes the code to handle the links
                                      }];

        return urlWasHandled;
    }

    // A function for parsing URL parameters returned by the Feed Dialog.
    - (NSDictionary*)parseURLParams:(NSString *)query {
        NSArray *pairs = [query componentsSeparatedByString:@"&"];
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        for (NSString *pair in pairs) {
            NSArray *kv = [pair componentsSeparatedByString:@"="];
            NSString *val =
            [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            params[kv[0]] = val;
        }
        return params;
    }


    - (void)postSuccess{

        NSLog(@" post success");
    }

希望有人能帮助我

4

1 回答 1

1

看起来您正在canPresentShareDialogWithParams:使用真正的参数进行调用,但是在实际呈现对话框时,您正在使用nil链接调用它,这可能就是没有显示的原因。

presentShareDialogWithParams:clientState:handler:您应该使用您创建的参数调用该方法。

[FBDialogs presentShareDialogWithParams:params 
                            clientState:nil
                                handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {...}];
于 2015-05-29T17:14:35.213 回答