2013-11-26 45 views
1

我很新的將Facebook整合到iOS應用程序。我已經閱讀了3本書,研究了Facebook的例子,並研究了Facebook教程,並且我不瞭解Facebook的整合。我瞭解如何在Facebook上註冊應用程序,但我不明白的是將文本和圖片發佈到用戶新聞源的代碼。我試圖瞭解Facebook的教程,但它們都基於Xcode和iOS版本,這些版本不是最新的。 Facebook的教程也不一致(例如,登錄教程與發佈教程等變量不匹配)。我確實懂得如何將文本添加到「initialText」,但它違背了Facebook政策,在此變量中提供默認文本。任何人都可以解釋如何在Xcode中發佈文本和圖片給用戶的新聞提要嗎?我如何發佈文字和圖片到Facebook新聞源

Thanx!

+0

你想使用蘋果提供的原生框架嗎? –

+0

我可以那樣做,是的。我一直在試圖瞭解Facebook的,但我會接受使用蘋果的框架。 – Scuttle

+0

有沒有人有使用Facebook框架的例子? – Scuttle

回答

0

在您的項目中導入社交框架。

- (void)ShareOnFB  
{   
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
     if (result == SLComposeViewControllerResultCancelled) { 

      NSLog(@"Cancelled"); 

     } else 

     { 
      NSLog(@"Done"); 
      //Adding the Text to the facebook post value from iOS 

     } 

     [controller dismissViewControllerAnimated:YES completion:Nil]; 
    }; 
    controller.completionHandler =myBlock; 

    NSString *fb=[NSString stringWithFormat:@"you can add your text hereand change it as and when needed"]; 

    [controller setInitialText:fb];  



    //Adding the Image to the facebook post value from iOS 

    [controller addImage:yourImageView.image]; 


    [self presentViewController:controller animated:YES completion:Nil]; 


} 
+0

我以爲:[controller setInitialText:fb]; Facebook政策不被接受? – Scuttle

+0

是的,這應該發佈圖像和文字在fb上。您可以動態更改初始文本而不是靜態文本。 – wasim

1

你試過這個嗎?

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { 

      SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 

      SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
       if (result == SLComposeViewControllerResultCancelled) { 

        NSLog(@"ResultCancelled"); 

       } else 

       { 
        NSLog(@"ResultSuccess"); 
       } 

       [controller dismissViewControllerAnimated:YES completion:Nil]; 
      }; 
      controller.completionHandler =myBlock; 
      [controller setInitialText:@"Learn iOS6 Social Framework integration"]; 
      [controller addURL:[NSURL URLWithString:@"http://google.com"]]; 
      [controller addImage:[UIImage imageNamed:@"myimage.jpeg"]]; 
      [self presentViewController:controller animated:YES completion:Nil]; 

     } 
     else{ 

      //NSLog(@"UnAvailable"); 
      UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Facebook" 
                  message:[NSStringstringWithFormat:@"The application cannot post message at the moment. Please login under setting section with your Facebook account."] 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
      [alert show]; 
      [alert release]; 
     } 
+0

您需要爲此添加社交框架。 –

相關問題