2013-08-30 2 views
1

Если я использую TWTweetComposeViewController или социальную инфраструктуру для твиттера, появляется по умолчанию твит-лист для публикации твита. Я не хочу, чтобы диалоговое окно Tweetsheet появилось, и я хочу отправить твит, не используя это. Как мне это сделать?Отправить твит через приложение без tweetsheet в iPhone

ответ

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

+0

работал большой ... но еще одна вещь, вместо твита, я хочу опубликовать URL-адрес, и поэтому он говорит: «Не удалось опубликовать твит на твиттере» Я думаю, что длина символа превышена. Если да, то как еще я могу отправить URL-адрес в виде твита? –

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

попробовать этот код ...