2012-11-05 24 views
0

我對iOS開發非常新。我做了一個應用程序,我需要將twitter和Facebook集成到牆壁發佈。 我已經完成了所有需要的編碼,並在模擬器上工作正常,但不是在設備上。臉書和微博集成到iPhone應用程序不工作的iPhone應用程序

作爲Facebook集成編碼的另一個問題,我從其他「演示」應用程序中複製了它。還有什麼我們需要在其中更改以使其適用於我自己的應用程序。因爲當我看到我的更新完成在Facebook牆上的應用程序,「演示」應用程序的名字隨着這篇文章而來。

請引導我!!感謝您提前!

回答

1

Facebook的

看來你閱讀文檔之前已躍升至編碼部分。在集成facebook sdk並編寫代碼之前,您需要在Facebook開發者控制檯中創建一個新的應用程序部分,獲取Facebook應用程序ID。您需要在您的項目中使用該應用程序ID,而不是與facebook演示應用程序一起提供的應用程序ID。

Documentation完全解釋了這個過程,不需要在這裏重寫。確保你閱讀到最後。

Twitter的

我不知道,如果您有在Twitter上也問題(問題是對不清楚)。如果是的話,你應該告訴你如何連接到Twitter。但總的來說,從你的問題的口氣來看,你似乎沒有閱讀文檔,在各自的開發人員控制檯中創建應用程序部分,並獲取應用程序ID。

+0

感謝兄弟至少讀它的幾個問題之後solved.But我仍MOT能夠找到爲什麼Facebook和與我的設備,即iPhone應用Twitter的5沒有工作,但在它的模擬器工作正常。 – Sawant

0

我不知道你需要多少集成,或者你是否願意需要iOS 6,但是在iOS 6中,集成Facebook和Twitter更容易。

這是所有代碼:

在頭文件:

#import "Social/Social.h" 

在主文件:

//Twitter 
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { 
     SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 

     SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
      if (result == SLComposeViewControllerResultCancelled) { 
       NSLog(@"Cancelled"); 
      } else { 
       NSLog(@"Done!"); 
      } 

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

     [controller setInitialText:@"Status Text"]; 

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

    } else { 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now. You must be online and signed into at least one Twitter account." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alertView show]; 
    } 

    //Facebook 
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { 

     SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 

     SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
      if (result == SLComposeViewControllerResultCancelled) { 
       NSLog(@"Cancelled"); 
      } else { 
       NSLog(@"Done!"); 
      } 

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

     [controller setInitialText:@""]; 

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

    } else { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook Error" message:@"Either you are not logged into Facebook or your Facebook username and password are incorrect." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     [alert show]; 
    } 
+0

我可以知道你使用了哪個第三方框架嗎?你需要做什麼? –

0

按照在您的應用程序中整合推特。請嘗試以下代碼

at self.fullimage寫任何圖像的URL。

調用buildTweetSheet方法發佈到twitter。

導入Twitter。框架

進口

@屬性(非原子,強)TWTweetComposeViewController * _tweetSheet;

@synthesize _tweetSheet; (無效)buildTweetSheet { NSLog(@「buildTweetSheet」);

_tweetSheet = [[TWTweetComposeViewController alloc] init]; 


UIImage *eimage=UIImage *eimage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.fullimage]]]; 





[_tweetSheet setInitialText:@""]; 

[_tweetSheet addImage:eimage]; 

[_tweetSheet setInitialText:@""]; 

[self presentModalViewController:_tweetSheet animated:YES]; 

TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result) 

{ 
    if(result == TWTweetComposeViewControllerResultDone) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Done" message:@"Image Posted Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 

    } 
    else { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"Image Posted Failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 

    } 

    [self dismissModalViewControllerAnimated:YES]; 
}; 

[_tweetSheet setCompletionHandler:completionHandler]; 

}