Send tweet via app without the tweetsheet in iPhone

北城以北 提交于 2019-12-12 09:24:22

问题


If I use the TWTweetComposeViewController or the social framework for twitter, the default tweet sheet appears for posting the tweet. I dont want that tweetsheet dialog to popup and I want to send the tweet without using that. How can I do it?


回答1:


You can this with trick. i did this in my project and i put this method Bellow hope this Help's you

-(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];
    }
}

please take a look very nice explanation about TWTweetComposeViewControllerClass




回答2:


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];
        }

try this code...



来源:https://stackoverflow.com/questions/18531247/send-tweet-via-app-without-the-tweetsheet-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!