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.
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];
The issue was apparently fixed in iOS 7, tested on 7.0 beta build 11A4449d.
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");}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With