【问题标题】:Twitter in ios6 Social framework method completeios6社交框架中的twitter方法完成
【发布时间】:2013-09-14 01:24:13
【问题描述】:

我通过以下方式向 twitter 发布消息:

 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{



//  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:@"Download Cleverly at "];

//  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:@"iTunesArtwork120.png"]]) {
    NSLog(@"Unable to add the image!");
}

//  Add an URL to the Tweet.  You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/cleverly/id703006076?ls=1&mt=8"]]){
    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.");
}];
}
}

我想运行这个方法:

NSInteger highScore = [[NSUserDefaults standardUserDefaults] integerForKey:@"SharingsLeft"];
if (highScore != 999999999) {
[[NSUserDefaults standardUserDefaults] setInteger:highScore + 5 forKey:@"SharingsLeft"];
[self.SendCounter setTitle:[NSString stringWithFormat:@"%ld", (long)highScore] forState:UIControlStateNormal];

仅当用户实际发布推文时。但是,当推文发布或用户按下“发布”按钮时,该块中没有任何方法可以通知我。

【问题讨论】:

    标签: ios twitter


    【解决方案1】:
    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;
        }
    
    };
    

    如果您阅读正确SLComposeViewControllerResultDone 是当用户按下发送/发布表单时,您可以在此处添加您想要在用户成功发布时调用的方法调用

    更多信息在文档here

    【讨论】:

    • 所以我需要将代码放在 case SLComposeViewControllerResultDone: 和 break 之间?
    【解决方案2】:
           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;
             }
    
     };
    

    完全同意但丁

    【讨论】:

      猜你喜欢
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      • 2012-10-05
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      相关资源
      最近更新 更多