2012-03-30 59 views
2

发布没有弹出对话框我想发布在Twitter墙上,但不希望该用户可以编辑发布的消息。我想通过TWTweetComposeViewController

所以在两个可能做到这一点

1)任我可以TWTweetComposeViewController文本字段不可编辑。

2)由TWTweetComposeViewController发布无POP。

请建议我如何做到以上的选项或任何其他想法是最受欢迎的。

先感谢您的任何一种Suggetions的....

+0

看起来这正是你想要的东西:http://stackoverflow.com/questions/9423447/ios-5-twitter-framework-tweeting-without-user-input-and-confirmation-modal-vie – rosslebeau 2012-03-30 11:41:11

+0

您可以使用第一个选项。 – 2012-03-30 11:41:22

+0

如果您计划通过Twitter整合TwitterKit以通过您的自定义推特应用执行推文,那么这可能会对您有所帮助。 http://stackoverflow.com/a/28602749/1740354 – 2015-02-19 09:39:09

回答

3

我有下面的代码这样做...

-(void)postToTwittert:(NSString *)stringtoPost 
{  
    Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController"); 

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

      [twitter setInitialText:stringtoPost]; 

      [twitter addImage:[UIImage imageNamed:@"apple.jpg"]]; 
      [twitter addURL:[NSURL URLWithString:@"http://www.erwinzwart.com"]]; 
      [self findSubViewofTwitter:twitter.view]; 
      [self presentViewController:twitter animated:YES completion:nil]; 

      twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) { 

       if(res == TWTweetComposeViewControllerResultDone) 
       { 
        [self completeGameStep:@"glueper2012"];      

       } 
       else if(res == TWTweetComposeViewControllerResultCancelled) 
       { 

        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Canceled" message:@"Your Tweet was not posted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

        [alertView show]; 

       } 

       [self dismissModalViewControllerAnimated:YES]; 

      }; 
     } 
    } 
} 

通过查找按钮,点火事件

- (void) findSubViewofTwitter:(UIView*)theView 
{ 
    for (UIView * subview in theView.subviews) 
    { 
     //NSLog(@">>>>>>>>>>>>>>>>>> :%@", subview); 
     if ([subview isKindOfClass:[UIButton class]]) 
     { 
      UIButton *btn = (UIButton *)subview; 
      //NSLog(@">>>>>>>>>>>>>> is kind of class :%@", btn.titleLabel.text); 
      if([btn.titleLabel.text isEqualToString:@"Send"]) 
      { 
       [btn sendActionsForControlEvents:UIControlEventTouchUpInside]; 
      } 
     } 
     [self findSubViewofTwitter:subview]; 
    } 
} 
3

我修改了你的函数“findSubViewofTwitter”,以便在不等待用户按下发送的情况下不发送推文。我的功能只是使不可编辑的UITextView。

- (void) findSubViewofTwitter:(UIView*)theView 
{ 
    for (UIView * subview in theView.subviews) 
    { 
     if ([subview isKindOfClass:[UITextView class]]) 
     { 
      UITextView *textView = (UITextView *)subview; 
      textView.editable = NO; 
      return; 
     } 
     [self findSubViewofTwitter:subview]; 
    } 
}