Assuming that you were trying to use presentViewController
's completion handler and getting incorrect results, here's an alternative way. You can present the first composer as you normally would, but then in the composer's completion block, present a second composer. This completion handler is called as soon as the first composer is done being dismissed.
In the example I've set up below, the second composer will only be presented if the first returns SLComposeViewControllerResultDone
, allowing you to close out all together in the event that the user hits cancel. However, if you don't want this functionality it can be removed painlessly by keeping the logic for presenting the second composer, but removing the switch statement all together. This code is tested and should produce the results you're looking for. Hope it helps!
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookComposer setInitialText:@"facebook"];
[facebookComposer setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(@"Post Canceled, bail out");
break;
case SLComposeViewControllerResultDone:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *twitterComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterComposer setInitialText:@"twitter"];
[twitterComposer setCompletionHandler:^(SLComposeViewControllerResult result) {
NSLog(@"done with both sharing options");
}];
[self presentViewController:twitterComposer animated:YES completion:nil];
}
break;
default:
break;
}
}];
[self presentViewController:facebookComposer animated:YES completion:nil];
}