Question

I have some social sharing code that looks like this:

SLComposeViewController *composer = [SLComposeViewController composeViewControllerForServiceType:…];
[composer setInitialText:…];
[composer addURL:…];
[composer setCompletionHandler:^(SLComposeViewControllerResult result) {
    [someController dismissViewControllerAnimated:YES completion:^{
        … // 1
    }];
}];
[someController presentModalViewController:composer animated:YES];

The problem is that the code behaves differently for Facebook and Twitter. When the user confirms the Facebook compose screen, the composer apparently dismisses itself, because the completion handler marked as 1 is never called and even when I remove the dismissViewControllerAnimated: call, everything works fine.

On the other hand, when user confirms the Twitter compose screen and I don’t dismiss it by hand, the compose screen slides out, but the app stays stuck, like some controller is still in foreground. When I add the dismissViewControllerAnimated: call, the problem disappears and the completion handler (1) is called correctly.

Did you also notice this behaviour? Am I doing something wrong? This is current iOS 6, sample code on GitHub. I have reported the problem to Apple (Radar #12642889), no reaction yet.

Was it helpful?

Solution 2

The issue was apparently fixed in iOS 7, tested on 7.0 beta build 11A4449d.

OTHER TIPS

I'm doing something similar in my app, and the only difference to your code is that I'm sending dismissModalViewControllerAnimated: to self instead of sending it to the view controller.
Both facebook and twitter composer slide away.

This is my code:

SLComposeViewController *composer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composer setInitialText:text];
[composer setCompletionHandler:^(SLComposeViewControllerResult result) {
    ...
    [self dismissModalViewControllerAnimated:YES];
}];
[self presentModalViewController:composer animated:YES];

I have confirmed your issue with the behavior:

The Twitter version calls the completion handler that you set on the view controller, and expects that you will call dismissViewController from within this handler.

However the Facebook version calls dismissViewController itself before calling your completion handler. If you then call dismissViewController yourself, nothing happens, and you don't get any callback from any completion block that you might pass to dismissViewController.

If you leave out the dismissViewController call, then Twitter sharing gets stuck, but Facebook works.

Its a problem to create a solution if Apple is going to fix the behavior since your solution would then get broken. The main problem is that the behavior is not the same between the Weibo, Twitter and Facebook sharing versions of the same social sharing VC.

Here is how I fixed the problem:

SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:serviceType];
if(vc==nil)
{
    [self.delegate imageSaveDidSucceed:NO];
}
else
{
    [vc addImage:self.image];
    vc.completionHandler = ^(SLComposeViewControllerResult result) {
        DEBUG_LOG(@"social sharing completed");
        if(self.presentedViewController)
        {
            DEBUG_LOG(@"presented vc is not nil");
            [self dismissViewControllerAnimated:YES completion:^{
                DEBUG_LOG(@"dismissed vc and calling imageSaveDidSucceed");
                [self.delegate imageSaveDidSucceed:YES];
            }];
        }
        else
        {
            DEBUG_LOG(@"presented vc is nil");
            [self.delegate imageSaveDidSucceed:YES];
        }
    };
    [self presentViewController:vc animated:YES completion: ^{DEBUG_LOG(@"vc was presented");}];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top