1

如果我使用TWTweetComposeViewController或 twitter 社交框架,则会显示默认的推文表以发布推文。我不想弹出那个推文对话框,我想在不使用它的情况下发送推文。我该怎么做?

4

2 回答 2

0

你可以用技巧来做到这一点。我在我的项目中做了这个,我把这个方法放在下面希望这对你有帮助

-(void)TwitteFromShareBtnApear
{

        Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");

        if (TWTweetComposeViewControllerClass != nil) {
            if([TWTweetComposeViewControllerClass respondsToSelector:@selector(canSendTweet)]) {
                TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];



                [twitter setInitialText:@"twitter text"];

               [twitter addImage:[UIImage imageNamed:@"icon.png"]];
                [twitter addURL:[NSURL URLWithString:self.strsmallUrl]];
            [self findSubViewofTwitter:twitter.view];
            [self presentViewController:twitter animated:YES completion:nil];

                twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {

                    if(res == TWTweetComposeViewControllerResultDone)
                    {

                     //done alert


                    }
                    else if(res == TWTweetComposeViewControllerResultCancelled)
                    {
                    //cancel alert
                    }

                    [self dismissModalViewControllerAnimated:YES];

                };
            }
        }

}
- (void) findSubViewofTwitter:(UIView*)theView
{
    for (UIView * subview in theView.subviews)
    {
        subview.hidden=TRUE;

        if ([subview isKindOfClass:[UIButton class]])
        {
            UIButton *btn = (UIButton *)subview;

            if([btn.titleLabel.text isEqualToString:@"Send"])
            {
                [btn sendActionsForControlEvents:UIControlEventTouchUpInside];
            }
        }
        [self findSubViewofTwitter:subview];
    }
}

请看一下关于TWTweetComposeViewControllerClass的非常好的解释

于 2013-08-30T11:01:29.710 回答
-1
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

        [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
            if (granted) {

                NSArray *accounts = [accountStore accountsWithAccountType:accountType];
                twitterAccount = [accounts objectAtIndex:0];
            }
        }];

        if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
        {
            SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
            [tweetSheet setInitialText:@"tweeting from my own app! :)"];
            [tweetSheet addURL:[NSURL URLWithString:@"www.web.com"]];
            [self presentViewController:tweetSheet animated:YES completion:nil];
        }
        else
        {
            UIAlertView *alertView = [[UIAlertView alloc]
                                      initWithTitle:@"Sorry"
                                      message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
                                      delegate:self
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];
            [alertView show];
        }

试试这个代码...

于 2013-08-30T11:04:00.703 回答