Ios “错误”;选择器'的类方法未知;canSendTweet';

Ios “错误”;选择器'的类方法未知;canSendTweet';,ios,objective-c,twitter,Ios,Objective C,Twitter,我正在尝试设置一个tweet按钮。我所有的代码似乎都正常工作,除了它给了我一个错误“选择器‘canSendTweet’没有已知的类方法”有什么建议吗 - (IBAction)tweetTapped:(id)sender { //Check if the device can send tweets if ([SLComposeViewController canSendTweet]) { //Create tweet sheet and set initial text SLCom

我正在尝试设置一个tweet按钮。我所有的代码似乎都正常工作,除了它给了我一个错误“选择器‘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

对于类
SLComposeViewController
,没有名为
canSendTweet
的类方法。快速查看参考文档(您应该这样做)会发现您想要的是:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    // can send a tweet
}
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    // can send a tweet
}
这是来自Twitter.framework的方法(您必须导入此框架)

您可以在Social.framework中使用此方法来检查“用户可以tweet吗?”

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