1
votes

This question look duplicate and ye it is 50% duplicate because there is no good answer I found any where.

let me divide my question in three part.

Current Situation: I have implemented sign up screen with Email, Date of birth, Gender and Zipcode.
This is working very nice. I have also implement share feature in facebook and twitter in iOS 5 and 6
But now I want to implement it with facebook and twitter like
shown in following example screen:

Login With Facebook

What is problem: I want to know how can I implement login with facebook in iOS 5. twitter is integrated with ios 5 and 6, Facebook with iOS 6 so that is not big deal (right now I think so). I have already implemented share feature for both twitter and facebook for iOS 5 & 6. so what more I need to do to implement login.

What I get in response: As I said I need Email, Date of birth, Gender and Zipcode at time of signup. How can I get this information if I use login with facebook and twitter. What should I do if user have not given or block this information of this social site.

Thanks.......

2

2 Answers

5
votes

Here is how I implemented this feature in my app:

  1. Download the Facebook SDK for iOS from here

  2. In your AppDelegate.h make a property of the Facebook object.

    #import <UIKit/UIKit.h>
    #import "Facebook.h"
    
    @interface OutpearAppDelegate : NSObject <UIApplicationDelegate> {
        UIWindow *window;
        IBOutlet UINavigationController *navigationController;        
    }
    
    @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) Facebook *facebook;
    +(DemoAppDelegate*)getAppDelegate;
    
  3. In your AppDelegate.m write this:

    synthesize facebook;
    

    and in your applicationDidFinishLaunching method write this:

    // Initialize Facebook with app ID
    facebook=[[Facebook alloc]initWithAppId:FB_APP_KEY andDelegate:nil];
    //here FB_AP_Key is your Facebook application key
    

    and release facebook in dealloc

  4. Where you want to login with Facebook write this function:

    - (void)loginWithFacbookIdClicked
    {
        [DemoAppDelegate getAppDelegate].facebook.sessionDelegate=self;
    
        if(isInternetAvailable)
        {
            if([[DemoAppDelegate getAppDelegate].facebook isSessionValid])
            {
                //[facebookIntegration getUserFacebookPersonalInfo];
                 NSLog("User already logined with facebook");
            }
            else
            {
                [[DemoAppDelegate getAppDelegate].facebook authorize:[NSArray arrayWithObjects:@"read_stream",
                                     @"publish_stream",
                                     @"email",
                                     @"user_birthday",
                                     @"friends_about_me",
                                     @"friends_activities",
                                     @"friends_likes",
                                     nil]];
            }
        }
        else
        {
           NSLog("No Internet Connection");
        }       
    }
    
  5. After login, the Facebook SDK delegate methods are automatically called. Do your stuff in delegate methods.

    - (void)fbDidLogin
    {
       NSLog("Logged into Facebook");
       // Your logic goes here.   
    }
    
    -(void)fbDidNotLogin:(BOOL)cancelled
    {
        DLog(@"Login Cancelled");
    }
    
    -(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt
    {
    
    }
    
    -(void)fbSessionInvalidated
    {
    
    }
    
    -(void)fbDidLogout
    {
    
    }
    
2
votes

Easiest way is to pull this link from github. It contains a few sample code. That will help you up and running in no time. Also check out this Facebook tutorial and this