Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to share posts in Facebook by using SLComposeViewController in iOS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 449
    Comment on it

    We can share post in Facebook by using following steps:

    Add one button on ViewController and give action to it.

    Import #import <Social/Social.h>

    Now in button action write following code.

     - (IBAction)facebookButtonAction:(id)sender {
        
        SLComposeViewController *controller = [SLComposeViewController
                                               composeViewControllerForServiceType:SLServiceTypeFacebook];
        SLComposeViewControllerCompletionHandler myBlock =
        ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled)
            {
                NSLog(@"Cancelled");
            }
            else
            {
                NSLog(@"Done");
            }
            [controller dismissViewControllerAnimated:YES completion:nil];
        };
        controller.completionHandler =myBlock;
        //Adding Text to the facebook post
        [controller setInitialText:@"My test post"];
        //Adding URL to the facebook post 
        [controller addURL:[NSURL URLWithString:@"http://www.test.com"]];
         
        [self presentViewController:controller animated:YES completion:nil];
        
        
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: