2012-03-30 58 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]; 
    } 
}