SLComposeViewController CompletionHandler [英] SLComposeViewController CompletionHandler

查看:207
本文介绍了SLComposeViewController CompletionHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用SLComposeViewController CompletionHandler完成推文,我该如何收到通知。以下是发送推文的代码

Hi how do I get notified if a tweet was completed using the SLComposeViewController CompletionHandler. Here is the code to send a tweet

  if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        [tweetSheet setInitialText:@"Tweeting from my own app! :)"];
        [tweetSheet addURL:[NSURL URLWithString:@"www.someurl.com"]];

        [self presentViewController:tweetSheet animated:YES completion:NULL];
    }


推荐答案

找到答案

- (void)showTweetSheet
{
  //  Create an instance of the Tweet Sheet
  SLComposeViewController *tweetSheet = [SLComposeViewController
                                         composeViewControllerForServiceType:
                                         SLServiceTypeTwitter];

  // Sets the completion handler.  Note that we don't know which thread the
  // block will be called on, so we need to ensure that any UI updates occur
  // on the main queue
  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;
    }

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

  //  Set the initial body of the Tweet
  [tweetSheet setInitialText:@"just setting up my twttr"];

  //  Adds an image to the Tweet.  For demo purposes, assume we have an
  //  image named 'larry.png' that we wish to attach
  if (![tweetSheet addImage:[UIImage imageNamed:@"larry.png"]]) {
    NSLog(@"Unable to add the image!");
  }

  //  Add an URL to the Tweet.  You can add multiple URLs.
  if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
    NSLog(@"Unable to add the URL!");
  }

  //  Presents the Tweet Sheet to the user
  [self presentViewController:tweetSheet animated:NO completion:^{
    NSLog(@"Tweet sheet has been presented.");
  }];
}

这篇关于SLComposeViewController CompletionHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆