用户通过iOS6“推文表”推文后触发动作

时间:2013-05-29 23:52:03

标签: ios objective-c cocoa-touch ios6

我希望在用户通过iOS6的内置“推文表”推文后触发特定操作

Tweet Sheet

我想在用户点击“发送”按钮后触发一个方法。

或者,如果我可以从iOS收到一些确认成功发布推文的确认,那么我想触发该方法。

这些选项中的任何一个都可以吗?在用户发布推文后,是否有不同的首选方式触发操作?

2 个答案:

答案 0 :(得分:2)

-(void)shareViewTwitter:(NSString*)str
{
    TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];

    // Optional: set an image, url and initial text

    [twitter setInitialText:@"Some Text"];

    // Show the controller
    [self presentModalViewController:twitter animated:YES];

    // Called when the tweet dialog has been closed (Here your Action will be triggered)
    twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
    {
        NSString *title = @"Tweet Status";
        NSString *msg;

        if (result == TWTweetComposeViewControllerResultCancelled)
// Your Action

            msg = @"Tweet compostion was canceled.";
        else msg = @"Tweet composition completed."; // Your Action

        // Show alert to see how things went...
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
        [alertView show];

        // Dismiss the controller

        [self dismissModalViewControllerAnimated:YES];

    };

}

答案 1 :(得分:1)

使用完成处理程序。请参阅下面的代码示例。

SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
    switch(result) {
        //  This means the user cancelled without sending the Tweet
        case SLComposeViewControllerResultCancelled:
            break;
        //  This means the user hit 'Send'
        case SLComposeViewControllerResultDone:
            break;
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:NO completion:^{
            NSLog(@"Tweet Sheet has been dismissed.");
        }];
    });
};
  

来源:https://dev.twitter.com/docs/ios/using-tweet-sheet