2

この質問が何度も投稿されていることは知っていますが、本当に問題を解決できる提案はありませんでした。この問題で 2 日間を無駄にしましたが、今まで解決策がありませんでした。貴重なご指導をお願いします。

Facebookにステータスを投稿したい。

  if ([PostType isEqual:@"article"])
    {

        [dict setObject:PostTitle forKey:@"message"];
        params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                  PostTitle, @"message", nil];

        if (FBSession.activeSession.isOpen) {

            // Yes, we are open, so lets make a request for user details so we can get the user name.
            if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {

                [[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObjects: @"publish_actions",nil] defaultAudience:FBSessionDefaultAudienceFriends
                                                      completionHandler:^(FBSession *session,NSError *error){
                                                          [self promptUserWithAccountName];
                                                      }];

            }else{
                [self promptUserWithAccountName];
            }

            // a custom method - see below:



        } else {


            NSArray *permissions = [[NSArray alloc] initWithObjects:
                                    @"publish_actions",
                                    nil];

            // OPEN Session!
            [FBSession openActiveSessionWithPermissions:permissions
                                           allowLoginUI:YES
                                      completionHandler:^(FBSession *session,
                                                          FBSessionState status,
                                                          NSError *error) {
                                          // if login fails for any reason, we alert
                                          if (error) {

                                              // show error to user.

                                          } else if (FB_ISSESSIONOPENWITHSTATE(status)) {

                                              // no error, so we proceed with requesting user details of current facebook session.

                                              [self promptUserWithAccountName];   // a custom method - see below:
                                          }

                                      }];  
        }

カスタム方法:

 -(void)promptUserWithAccountName {
[[FBRequest requestForMe] startWithCompletionHandler:
 ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
     if (!error) {

         [FBRequestConnection startWithGraphPath:@"me/feed"
                                      parameters:params
                                      HTTPMethod:@"POST"
                               completionHandler:^(FBRequestConnection *connection,
                                                   id result,
                                                   NSError *error){

                                   if (!error) {
                                       UIAlertView *tmp = [[UIAlertView alloc]
                                                           initWithTitle:@"Success"
                                                           message:@"Photo Uploaded"
                                                           delegate:self
                                                           cancelButtonTitle:nil
                                                           otherButtonTitles:@"Ok", nil];

                                       [tmp show];

                                   } else {
                                       UIAlertView *tmp = [[UIAlertView alloc]
                                                           initWithTitle:@"Error"
                                                           message:@"Some error happened"
                                                           delegate:self
                                                           cancelButtonTitle:nil
                                                           otherButtonTitles:@"Ok", nil];

                                       [tmp show];

                                   }


                               }];



     }



 }];

 }
4

0 に答える 0