How to post on facebook in iOS.


Q.76 How to post on facebook in iOS.?Ans:-

  • step 1- Select the singleView Application and give the name as ViewController& subClassOf UIViewController
  • step 2- Add framework. select project >> build phases >> Link Binary With Libraries and search  the “Social.framework” and click on add button agan one more time search and add “Accounts.framework”
  • step 3- in your viewController.h neccesary to import the framework.
  • in viewController.h

    #import <UIKit/UIKit.h>
    #import “Social/Social.h”
    #import “Accounts/Accounts.h”

    @interface ViewController : UIViewController
    {
    SLComposeViewController *mySLComoserSheet;
    }

    -(IBAction)PostToFacebook:(id)sender;

    @end

  • After that go on viewController.m

    #import “viewController.h”
    @interface viewController()
    @end

    @implementation viewController
    -(void)viewDidLoad
    {
    [super viewDidLoad];
    }
    -(IBAction)PostToFacebook:(id)sender
    {

    mySLComoserSheet = [[SLComposeViewController alloc]init];
    mySLComoserSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [mySLComoserSheet setInitialText:@”Hellow Steve post on Facebook”];
    [self presentViewController:mySLComposerSheet animated:YES completion:NULL];

    }

  • step 4- this is a imporatant step. Select storybord > select viewController and add one Button in the view with the POST ON FB name.
  • after that don’t forgot the connection PostToFacebook action method to Button. select touchUpInside.
  • step 5 – using command+B build your project and command+R run ur project in simulator. run and test.

Kalavati Technologies Pvt Ltd