SLComposeViewController dismisses differently for Facebook and Twitter?
Asked Answered
P

3

18

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.

Palmitate answered 6/11, 2012 at 9:21 Comment(7)
I'm seeing the same behavior too. For now, I'm dismissing the view controller manually for Twitter and letting the system do it for Facebook.Postobit
I noticed this too, did you ever hear back?Otherwhere
I have submitted a bug report to Apple and included a link to the sample project on GitHub. Apple has only contacted me now, after some five weeks, to request a sample project (sigh). I’ll download the sample project off GitHub, add it to the issue and wait. I’ll post the details here if anything changes.Palmitate
The symptoms that I encountered were that after twitter was complete, the keyboard did not dismiss itself. Adding the conditional dismissViewController as @Postobit mentioned fixed it.Banas
@zoul, did you hear anything back from Apple?Lucania
@JakeLin, not a word.Palmitate
problem still exists in ios9.1Sump
P
2

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

Palmitate answered 26/8, 2013 at 8:44 Comment(3)
Is it? I have the same problem in iOS 6 Right now in Xcode 5.0.2. I have to manually dismiss Twitter view controller after the user has cancelled/posted.Olenta
Should be. Note that I said iOS 7, the bug doesn’t depend on Xcode version. If your’re running current Xcode with an older iOS release, you might still bump into it.Palmitate
problem still exists in ios9.1+Sump
B
2

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];
Bickford answered 26/12, 2012 at 23:17 Comment(0)
P
2

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

Palmitate answered 26/8, 2013 at 8:44 Comment(3)
Is it? I have the same problem in iOS 6 Right now in Xcode 5.0.2. I have to manually dismiss Twitter view controller after the user has cancelled/posted.Olenta
Should be. Note that I said iOS 7, the bug doesn’t depend on Xcode version. If your’re running current Xcode with an older iOS release, you might still bump into it.Palmitate
problem still exists in ios9.1+Sump
T
1

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");}];
}
Theory answered 1/7, 2013 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.