Wednesday, 9 April 2014

Integration Of Facebook in IOS

Step 1: Install the Facebook SDK for iOS

Download the SDK and install the package by following the instruction wizard. The default install location is ~/Documents/FacebookSDK.
Download


1. Login to facebook.
2. Go to https://developers.facebook.com
3. Create new App taping  "Create a New App".
4. Write down the Appid for further use in your code some where else.
5. Now Create new project with Xcode.
6. Add the  FacebookSDK.framework from /Documents/FacebookSDK
7. Make some changes in your plist.
 
  -> FacebookAppID
 -> URL types
 -> Display Name(Optional)
8. Import header #import <FacebookSDK/FacebookSDK.h>
9. Create a property in your header of view controller
 @interface ViewController : UIViewController
@property (strong, nonatomic) FBSession *session;
@end

10 . Check the session on viewDidLoad.

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (!self.session.isOpen)
    {
        // create a fresh session object
        self.session = [[FBSession alloc] init];
        [self.session openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error)
        {
            [self updateView];
        }];
    }
    else
    {
         [self updateView];
    }


}
11. If session is open then

- (void)updateView
{
  
    if (self.session.isOpen)
    {
        [FBRequestConnection startWithGraphPath:@"me/friends" parameters:[NSDictionary  dictionaryWithObjectsAndKeys:self.session.accessTokenData.accessToken,@"access_token", nil]  HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *conn ,id result ,NSError *err)
         {
             NSLog(@"%@",result);
         }];
        
    }
    else
    {
        
    }

}

No comments:

Post a Comment