Facebook Share Dialog in iOS

前端 未结 4 972
粉色の甜心
粉色の甜心 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:47

    - (IBAction)btn_facebook:(id)sender {
        [self performSelector:@selector(fb_func) withObject:nil afterDelay:0.0];
    }
    
    -(void)fb_func
    {
        // 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_link = @"";
                 NSLog(@"%@",str_link);
    
                 NSDictionary *params = @{
                                          @"name" :@"name",
                                          @"caption" : @"Description",
                                          @"description" :@"test",
                                          @"picture" : PostimageToPintresrAndFacebook,
                                          @"link" : @"url",
                                          };
    
                 // Invoke the dialog
                 [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                                        parameters:params
                                                           handler:
                  ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                      if (error) {
                          NSLog(@"Error publishing story.");
                      } else {
                          if (result == FBWebDialogResultDialogNotCompleted) {
                              NSLog(@"User canceled story publishing.");
                          } else {
                              NSLog(@"Story published.");
                          }
                      }}];
             }
         }];
        return;
    
    }
    

提交回复
热议问题