How to Post to Facebook on iOS 6 in Objective-C using ACAccountStore class

前端 未结 5 2130
无人及你
无人及你 2020-12-07 17:21

I want to know how to post a status message to Facebook on iOS 6 using the new frameworks on Xcode 4.5. Thanks! :)

5条回答
  •  旧时难觅i
    2020-12-07 17:27

    Ok guys, so I tweaked the original post, works for iOS 6/7. Change ServiceType, Alert Title and Message for Facebook. Enjoy!

    - (IBAction)tweetMessage:(id)sender {
    
    
      if(![SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) //check if Facebook Account is linked
      {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unable to Tweet!" message:@"Please login to Twitter in your device settings." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            return;
      }
      //self.mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
      self.mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
      [self.mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I found this Thing, check it out at this Place:\n %@ \n", [self someplace]]];
      [self.mySLComposerSheet addImage:self.photos.firstObject];
    
      [self presentViewController:self.mySLComposerSheet animated:YES completion:nil];
      //}
    
      [self.mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
            NSString *output;
            switch (result) {
                  case SLComposeViewControllerResultCancelled:
                        output = @"Action Cancelled";
                        break;
                  case SLComposeViewControllerResultDone:
                        output = @"Post Successfull";
                        break;
                  default:
                        break;
            } //check if everything worked properly. Give out a message on the state.
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Twitter" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
      }];
    }
    

提交回复
热议问题