//------------------------------------------------------------------------------
// facebook SDK 다운로드
//------------------------------------------------------------------------------
https://developers.facebook.com/docs/ios/getting-started


//------------------------------------------------------------------------------
// 아래의 3가지 파일을 프로젝트에 추가한다.
//------------------------------------------------------------------------------
FacebookSDKStrings.bundle
FBSDKCoreKit.framework
FBSDKLoginKit.framework


//------------------------------------------------------------------------------
// info.plist 파일에 정보추가 (4개)
//------------------------------------------------------------------------------
URL types (Array) > Item 0 (Dictionary) > URL Schemes (Array) > Item 0 (String) : fb<facebook app id>
FacebookAppID : <facebook app id>
FacebookDisplayName : <앱이름>
LSApplicationQueriesSchemes (Array) : Item 0 : fbapi
                                      Item 1 : fb-messenger-api
                                      Item 2 : fbauth2
                                      Item 3 : fbshareextension


//------------------------------------------------------------------------------
// AppDelegate 에 소스 추가
//------------------------------------------------------------------------------
#import <FBSDKCoreKit/FBSDKCoreKit.h>

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                        openURL:url
                                              sourceApplication:sourceApplication
                                                     annotation:annotation];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
  [FBSDKAppEvents activateApp];
}


//------------------------------------------------------------------------------
// 로그인 연동, 페이스북의 회원정보 가져오기
//------------------------------------------------------------------------------
- (IBAction)doFacebook:(UIButton*)sender
{
  // Facebook 로그인 결과를 처리할 블록
  void (^blockFBLoginManager) (FBSDKLoginManagerLoginResult *result, NSError *error);
  blockFBLoginManager = ^(FBSDKLoginManagerLoginResult *result, NSError *error)
  {
    // 에러 처리
    if(error)
    {
      return;
    }    

    // 취소 처리
    if(result.isCancelled)
    {
      return;
    }

    // Facebook에서 회원정보 가져왔을때 처리할 블록
    void (^blockFBGraphRequest) (FBSDKGraphRequestConnection* connection, id result, NSError* error);
    blockFBGraphRequest = ^(FBSDKGraphRequestConnection* connection, id result, NSError* error)
    {
      NSDictionary* dicResult = (NSDictionary*)result;
      NSLog(@"facebook id = [%@]", [dicResult objectForKey:@"id"]);
      NSLog(@"facebook name = [%@]", [dicResult objectForKey:@"name"]);
      NSLog(@"facebook email = [%@]", [dicResult objectForKey:@"email"]);
    };

    // Facebook에서 회원정보 가져오기
    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"id,name,email", @"fields", nil];
    FBSDKGraphRequest* fbGraphRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
                                                                          parameters:dic
                                                                         tokenString:result.token.tokenString
                                                                             version:nil
                                                                          HTTPMethod:@"GET"];
    [fbGraphRequest startWithCompletionHandler:blockFBGraphRequest];
  };

  // Facebook 로그인
  NSArray* aryFBPermission = @[@"public_profile", @"email"];
  FBSDKLoginManager* fbLoginManager = [[FBSDKLoginManager alloc] init];
  [fbLoginManager logInWithReadPermissions:aryFBPermission fromViewController:self handler:blockFBLoginManager];
}



      

         

반응형

'iOS 초보' 카테고리의 다른 글

Barcode 이미지 생성하기  (0) 2016.08.26
2D변환 animation, 3D변환 animation  (0) 2016.06.03
UITextField. Placeholder. 색 변경  (0) 2016.04.07
cocoapods 설치. 사용법  (0) 2015.11.05
iOS, autolayout, scrollview  (0) 2015.08.18
Posted by 돌비
,