我正在尝试设置推文按钮。我的所有代码似乎都在工作,除了它给我的错误“没有已知的选择器类方法'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
答案 0 :(得分:2)
类canSendTweet
没有名为SLComposeViewController
的类方法。快速浏览一下参考文档(你应该做的),可以看出你想要的是:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
// can send a tweet
}
答案 1 :(得分:0)
canSendTweet
这是来自Twitter.framework的方法(你必须导入这个框架)
你可以在Social.framework中使用这个方法来检查“用户可以发推文吗?”
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
// can send a tweet
}