Wednesday 3 October 2012

Integrate a FaceBook Code for iOS

Step 1 : Add the Frame Works are  -- >    Social.framework     

Step 2 : Add the header files are  -- >       #import <Social/Social.h>

Step 3 : Add the Coding are

.h File


#import <UIKit/UIKit.h>
#import <Twitter/Twitter.h>
#import <Social/Social.h>

@interface sample : UIViewController
{
         IBOutlet UIButton * FaceBook;
}

-(IBAction)FaceBook:(id)sender;

@end.



.m File
-(IBAction) FaceBook:(id)sender
{
            SLComposeViewController *fbController=[SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
 
 
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
         
            [fbController dismissViewControllerAnimated:YES completion:nil];
         
            switch(result){
                case SLComposeViewControllerResultCancelled:
                default:
                {
                    NSLog(@"Cancelled.....");
                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Cancelled" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
                    [alert show];
                    [alert release];
                }
                    break;
                case SLComposeViewControllerResultDone:
                {
                    NSLog(@"Posted....");
                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Message Posted Succesfully" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
                    [alert show];
                    [alert release];
                }
                    break;
            }};
         fbController.completionHandler =completionHandler;
        [fbController addImage:[UIImage imageNamed:@"sample.png"]];
        [fbController setInitialText:@"Welcome to iPhone Developement Website."];
        [fbController addURL:[NSURL URLWithString:@"http://asanhussain.blogspot.in/"]];
        [fbController setCompletionHandler:completionHandler];
        [self presentViewController:fbController animated:YES completion:nil];
    }
    else{
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Message" message:@"Configure Your Setting" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        NSLog(@"UnAvailable");
    }

}



.xib File & Output:










No comments: