2013-03-17 2 views
2

저는 여전히 XCode 4.3.2 및 iOS 5.1 base SDK를 사용하고 있습니다. 내가 원하는 것은 iOS 5.0+ 기기 용 Facebook API를 통합하는 것입니다. 대신에 게시하고 기본 사용자 정보를 얻는 것과 같은 기본적인 기능.이전 버전의 Xcode 용 Facebook SDK와 iOS 5 및 iOS 6 모두 지원

페이스 북 SDK가 iOS 5에서 작동하는지, iOS 6에서 작동하는지는 알고 있지만 확실치 않습니다.

Facebook 통합에 신참으로, 누구든지이 문제에 대해 밝힐 수 있습니까? (프로젝트를 진행할 때 XCode와 iOS SDK를 업그레이드하는 것은 옵션이 아닙니다.)

  • 어떤 iOS SDK를 조사해야합니까?
  • 기본 SDK 5.1 및 XCode 4.3을 사용하여 iOS 5 및 6을 모두 지원할 수 있습니까?
  • iOS 버전을 지원하는 API가 있습니까?
  • Facebook 통합을위한 필수 항목은 무엇입니까? 그것은 또한 당신이주의 깊게 모든 하나 하나 N 구현 단계를 읽어 엑스 코드 4.3

    작동합니다

    1 단계에서

    http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/

    당신은 페이스 북 개발자에서 출판이 기사를 읽고 모든

답변

2

우선

6 단계에서 다음과 같이 코드를 작성합니다. Facebook Btn이 눌려진 곳

- (IBAction)facebookBtnPressed:(id)sender 
{ 


     // if it is available to us, we will post using the native dialog 
     BOOL displayedNativeDialog = [FBNativeDialogs presentShareDialogModallyFrom:self 
                     initialText:[NSString stringWithFormat:@"Here U write code which u want to post on facebook"] 
                       image:[UIImage imageNamed:@"1.jpg"] 
                       url:[NSURL URLWithString:@""] 
                      handler:nil]; 

     if (!displayedNativeDialog) 
     { 
      NSString *shareStr = [NSString stringWithFormat:@"Here U write code which u want to post on facebook"]; 
      NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys: 
              shareStr,@"description", 
              @"sharelink", @"link", 
              @"ImageName", @"picture", 
              nil]; 

      [self performPublishAction:^{ 

       [FBRequestConnection startWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 

        if (error) 
        { 
         NSLog(@"error in post"); 
        } 
        else 
        { 
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Post Successfully" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
         [alert show]; 
        } 

       }]; 
      }]; 
     } 
    //} 

    //===set delagate in Viewcontroller.h of mySLComposerSheet 
    [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) { 
     NSString *output; 
     switch (result) { 
      case SLComposeViewControllerResultCancelled: 
       output = @"Action Cancelled"; 
       break; 
      case SLComposeViewControllerResultDone: 
       output = @"Post Successfully"; 
       break; 
      default: 
       break; 
     } //check if everything worked properly. Give out a message on the state. 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alert show]; 
    }]; 
} 

- (void) performPublishAction:(void (^)(void)) action { 
    if ([[FBSession activeSession]isOpen]) { 
     /* 
     * if the current session has no publish permission we need to reauthorize 
     */ 
     if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) { 
      [[FBSession activeSession] reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] 
                 defaultAudience:FBSessionDefaultAudienceOnlyMe 
                 completionHandler:^(FBSession *session, NSError *error) { 
                  action(); 
                 }]; 
     }else{ 
      action(); 
     } 
    }else{ 
     /* 
     * open a new session with publish permission 
     */ 
     [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] 
              defaultAudience:FBSessionDefaultAudienceOnlyMe 
               allowLoginUI:YES 
             completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 
              if (!error && status == FBSessionStateOpen) { 
               action(); 
              }else{ 
               NSLog(@"error"); 
              } 
             }]; 
    } 
} 
+0

먼저 Social 및 AdSupport 프레임 워크가 없습니까? – Bartu

+0

u 코드를 'xcode'4.3으로 실행하면 Social 및 AdSupport 프레임 워크를 추가 할 필요가 없습니다 .iOS 6을 사용하면 iOS 5에서 작동하는 Optional로 두 프레임 워크를 모두 추가 할 수 있습니다. –

관련 문제