Try to dismiss a SLComposeViewController with a completion block and you will see that the block will not be called every time. Probably some kind of bug on iOS 6.
This code extends the SLComposeViewController class to make the controller run a block on dismissal and baby, this works. 😃
The same principle can be applied to any UIViewController that is not running the completion block on dismissal.
Using this:
-
import the header on your class
#import "SLComposeViewController+OnFinishing.h"
-
create a SLComposeViewController
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; // can be twitter or whatever
[controller setInitialText:myText]; [controller addURL:myURL]; [controller addImage:myImage];
-
set the onFinishing block using
myController.onFinishing = ^{ ... add here the code you want to run when this controller is dismissed };
-
set the completionHandler block to dismiss the controller
controller.completionHandler = ^(SLComposeViewControllerResult result){ [controller dismissViewControllerAnimated:YES completion:NULL]; };
-
present the controller
[self presentViewController:controller animated:YES completion:NULL];
that's it. Don't forget to import the social framework.