iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – SLComposeViewController CompletionHandler大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

嗨,如果使用SLComposeViewController CompletionHandler完成推文,我该如何收到通知。以下是发送推文的代码 if ([SLComposeViewController isAvailableForserviCEType:SLserviCETypeTwitter]) { SLComposeViewController *tweetSheet
嗨,如果使用SLComposeViewController CompletionHandler完成推文,我该如何收到通知。以下是发送推文的代码

if ([SLComposeViewController isAvailableForserviCEType:SLserviCETypeTwitter])
    {
        SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForserviCEType:SLserviCETypeTwitter];
        [tweetSheet seTinitialText:@"TweeTing from my own app! :)"];
        [tweetSheet addURL:[NSURL URLWithString:@"www@L_82_2@meurl.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.");
  }];
}

大佬总结

以上是大佬教程为你收集整理的objective-c – SLComposeViewController CompletionHandler全部内容,希望文章能够帮你解决objective-c – SLComposeViewController CompletionHandler所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:cobjective