尝试在用户发布到iOS中的FB后关闭显示SLComposeViewController的View Controller [英] Trying to dismiss View Controller that presents SLComposeViewController after user posts to FB in iOS

查看:212
本文介绍了尝试在用户发布到iOS中的FB后关闭显示SLComposeViewController的View Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示一个SLComposeViewController以便在我的应用程序中发布到Facebook.用户可以通过以下两种方式之一关闭此View Controller:通过将其帖子发布到Facebook或按取消".当用户按下取消"时,SLComposeViewController被解雇,并且用户返回到其后面的显示View Controller.

I am presenting an SLComposeViewController to post to Facebook in my app. The user is able to dismiss this View Controller in one of two ways: either by posting their post to Facebook, or by pressing "cancel". When the user presses "cancel", the SLComposeViewController is dismissed, and the user is returned to the presenting View Controller that is behind it.

但是,我想做的是,如果用户按下"post",那么我希望在SLComposeViewController被取消后(即在SLComposeViewControllerResultDone情况下)也取消正在显示的View Controller.我的问题是我不确定如何执行此操作.我意识到我会为此使用完成处理程序,但是我被困在这里.这是我显示SLComposeViewController的代码:

However, what I would like to do is if the user presses "post", then I want the presenting View Controller to ALSO be dismissed after the SLComposeViewController is dismissed (i.e. in the SLComposeViewControllerResultDone case). My problem is that I am not sure how to do this. I realize that I would use the completion handler for this, but I am stuck here. Here is the code that I have which presents the SLComposeViewController:

    SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [fbSheet setInitialText:initialText];
    [fbSheet addImage:myImage];

    SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result) {

    switch(result){
        case SLComposeViewControllerResultCancelled:
        default:
        {
            NSLog(@"Cancelled.....");

        }
            break;
        case SLComposeViewControllerResultDone:
        {
            NSLog(@"Posted....");
        }
            break;
    }

};

[fbSheet setCompletionHandler:completionHandler];

[self presentViewController:fbSheet animated:YES completion:nil];

有了上面的完成处理程序,我得到了预期的NSLog输出.但是,

With the completion handler above, I get the NSLog outputs as expected. However,

有人可以看到我在做什么错吗?正如我已经指出的那样,仅当用户发布"到Facebook时才需要关闭呈现的View Controller,而在他们取消时则不需要.

Can anyone see what it is I'm doing wrong? As I've pointed out, I need the dismissal of the presenting View Controller to occur ONLY if the user "posts" to Facebook, but NOT when they cancel.

推荐答案

您可以简单地在completionHandler的SLComposeViewControllerResultDone部分中关闭呈现的视图控制器,如下所示:

You could simply dismiss the presenting view controller in SLComposeViewControllerResultDone part of completionHandler as below:

    dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:YES completion:nil];
    });

如果您支持iOS 6,则需要先关闭SLComposeViewController.

If you are supporting iOS 6, then you need to dismiss the SLComposeViewController first.

这篇关于尝试在用户发布到iOS中的FB后关闭显示SLComposeViewController的View Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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