2013-09-24 34 views
0

我試圖設置一個tweet按鈕。我所有的代碼似乎都在工作,除了它給了我一個錯誤」沒有已知的選擇器類方法canSendTweet'「任何建議錯誤「沒有已知的類選擇器方法canSendTweet'

- (IBAction)tweetTapped:(id)sender 
{ 
//Check if the device can send tweets 
if ([SLComposeViewController canSendTweet]) 
{ 
    //Create tweet sheet and set initial text 
    SLComposeViewController *tweetSheet = 
    [[SLComposeViewController alloc] init]; 
    [tweetSheet setInitialText:@"this is a tweet from my app"]; 
    [tweetSheet addURL:[NSURL URLWithString:@"http://www.iosdeveloperguide.com"]]; 

    //show tweet sheet 
    [self presentViewController:tweetSheet animated:YES completion:nil]; 
} 
else 
{ 
    //Device can not tweet. Show error Notification. 
    UIAlertView *alertview = [[UIAlertView alloc] 
           initWithTitle:@"Unable to Tweet" 
           message:@"Please ensure that you have at least one Twitter account setup and have internet connectivity" 
           delegate:self 
           cancelButtonTitle:@"OK" 
           otherButtonTitles:nil]; 
    [alertview show]; 

} 

} 


@end 

回答

2

有一個名爲canSendTweet該類SLComposeViewController快速瀏覽一下參考文檔(你應該這樣做)沒有這樣的類方法表明你想要的是:?

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { 
    // can send a tweet 
} 
0
canSendTweet 

是從Twitter.framework的方法(你必須導入這個框架)

,你可以使用Social.framework此方法來檢查「用戶可以在Twitter?」

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { 
    // can send a tweet 
} 
相關問題