Facebook Share Dialog in iOS

前端 未结 4 1151
粉色の甜心
粉色の甜心 2021-01-14 05:56

I am trying to implement the native Share dialog from Facebook in a sample application.

Seem to have some problem in doing so.

Things I have done so far:

4条回答
  •  清歌不尽
    2021-01-14 06:38

    - (IBAction)shareButtonClicked:(id)sender
    {
        // if the session is closed, then we open it here, and establish a handler for state changes
    
        [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
         {
             if (error)
             {
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                 [alertView show];
             }
             else if(session.isOpen)
             {
                 NSString *str_img = [NSString stringWithFormat:@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
    
                 NSDictionary *params = @{
                                          @"name" :[NSString stringWithFormat:@"Facebook SDK for iOS"],
                                          @"caption" : @"Build great Apps",
                                          @"description" :@"Welcome to iOS world",
                                          @"picture" : str_img,
                                          @"link" : @"",
                                          };
    
                 // Invoke the dialog
                 [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                                        parameters:params
                                                           handler:
                  ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                      if (error) {
                          //NSLog(@"Error publishing story.");
                          [self.indicator stopAnimating];
                      } else {
                          if (result == FBWebDialogResultDialogNotCompleted) {
                              //NSLog(@"User canceled story publishing.");
                              [self.indicator stopAnimating];
                          } else {
                              //NSLog(@"Story published.");
                              [self.indicator stopAnimating];
                          }
                      }}];
             }
    
         }];
    
        return;
    }
    

提交回复
热议问题