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

前端 未结 5 2122
无人及你
无人及你 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条回答
  •  春和景丽
    2020-12-07 17:45

    And what do I have to do, when I just want to receive an alert in case the post was successful, and nothing when the user cancelled the post?

    And unfortunately this does not work properly for Twitter... It doesn't dismiss the TweetSheet anymore. Here is my code:

     if(NSClassFromString(@"SLComposeViewController") != nil)
     {
    
            mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
            mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; //Tell him with what social plattform to use it, e.g. facebook or twitter
            [mySLComposerSheet setInitialText:[NSString stringWithFormat:story.title,mySLComposerSheet.serviceType]]; //the message you want to post
            [mySLComposerSheet addURL:[NSURL URLWithString:story.link]];
            //for more instance methodes, go here:https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40012205
            [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
                NSString *output;
                switch (result) {
                    case SLComposeViewControllerResultCancelled:
                        output = NSLocalizedStringFromTable(@"As it seems you didn't want to post to Twitter", @"ATLocalizable", @"");
                        break;
                    case SLComposeViewControllerResultDone:
                        output = NSLocalizedStringFromTable(@"You successfully posted to Twitter", @"ATLocalizable", @"");
                        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];
            }];
            [self presentViewController:mySLComposerSheet animated:YES completion:nil];
    

提交回复
热议问题