Monday, July 16, 2012

Importance of SLComposeViewControllerCompletionHandler

You need to add the handler(SLComposeViewControllerCompletionHandler) otherwise you may get following error when you try to cancel the Facebook Post or post the Post:

viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceErrorDomain Code =1 "The operation couldn't be completed. (_UIViewServiceErrorDomain error 1.)"


You need to create handler like following

SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result)
{
            
            [fbController dismissViewControllerAnimated:YES completion:nil];
            
            switch(result){
            case SLComposeViewControllerResultCancelled:
            default:
            {
                NSLog(@"Cancelled.....");
                
            }
                break;
            case SLComposeViewControllerResultDone:
            {
                NSLog(@"Posted....");
            }
                break;
        }};


and add this handler to SLComposeViewController


SLComposeViewController *fbController=[SLComposeViewControllercomposeViewControllerForServiceType:SLServiceTypeFacebook];
[fbController setCompletionHandler:completionHandler];

and you can see the last post to see how to use it completely with the sample code. LINK.

No comments:

Post a Comment