Twitter发布iOS6'取消'按钮问题

时间:2012-09-27 08:49:17

标签: iphone ios xcode ios6 xcode4.5

我正在更改iOS6和iPhone使用的应用程序,我似乎无法弄清楚为什么当我使用新社交框架从Twitter发帖时我必须按下'取消'两次关闭,其他人有这个问题或修复?这是按钮的代码。

- (IBAction)twitterPost:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
    mySLComposerSheet = [[SLComposeViewController alloc] init];
    mySLComposerSheet = [SLComposeViewController   composeViewControllerForServiceType:SLServiceTypeTwitter];
    [mySLComposerSheet setInitialText:[NSString stringWithFormat:@"This is my tweet, hello!",mySLComposerSheet.serviceType]];
    [self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
    NSLog(@"dfsdf");
    switch (result) {
        case SLComposeViewControllerResultCancelled:
            break;
        case SLComposeViewControllerResultDone:
            break;
        default:
            break;
    }
}];


}

5 个答案:

答案 0 :(得分:18)

如果您使用mySLComposerSheet,那么效果很好......

[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];

答案 1 :(得分:9)

我对SLComposeViewController的体验是需要手动关闭twitter和微博控制器,而facebook控制器似乎表现得更好。

如果我自己不解雇ViewControllerAnimated,点击“发送”按钮将发送推文或微博发布,但我将留下看似我看不见的视图。因此,我无法再与我的应用互动。

我不知道为什么我的应用程序这样工作...有趣的是,cancel的completionHandler只被调用一次。第二次点击解除视图控制器。

+ (void) shareText:(NSString*)text image:(UIImage*)image social:(NSString*)service url:(NSString*)url
{
    SLComposeViewController*    controller = [SLComposeViewController composeViewControllerForServiceType:service];

    [controller setInitialText:text];
    [controller addImage:image];
    [controller addURL:[NSURL URLWithString:url]];

    controller.completionHandler = ^(SLComposeViewControllerResult result) {
        if( SLComposeViewControllerResultDone == result )
        {
            NSLog(@"rewards for share: %@!", service );
        }
        if( ![SLServiceTypeFacebook isEqualToString:service] )  // facebook behaves
            [[CBLAppDelegate instance].activeViewController dismissViewControllerAnimated:true completion:nil];
    };
    [[CBLAppDelegate instance].activeViewController presentViewController:controller animated:true completion:nil];
}

答案 2 :(得分:7)

发现了这个问题。它只在将完成处理程序添加到TWTweetComposeViewController时发生。如果添加,请务必致电:

[self dismissModalViewControllerAnimated:YES];

答案 3 :(得分:3)

试试这个好友

   [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

        switch (result) {
            case SLComposeViewControllerResultCancelled:
                [self performSelector:@selector(showalert)];
                [mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
                break;
            case SLComposeViewControllerResultDone:
                [self performSelector:@selector(showalert1)];
                [mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
                break;

            default:
                break;


        }
    }];

答案 4 :(得分:1)

在上面发表评论作为答案:

  

您是否尝试在显示视图控制器之前设置completionHandler?