When I use Post Notification then cancel button of Social framework don't hide Controller but hides alert

StackOverflow https://stackoverflow.com/questions/16396139

  •  14-04-2022
  •  | 
  •  

Pregunta

I am using social framework for sharing purposes.In IBAction of share Button I post a notification.But when i press cancel button of alert of Settings of particular social networking site then alert hides but keyboard and controller dont hide. I am using following code

- (IBAction)shareOnFB:(id)sender
{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"hideNotification" object:nil];
    SLComposeViewController *controllerSLC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [controllerSLC setInitialText:_dictShare[@"description"]];
    [controllerSLC addURL:[NSURL URLWithString:@"http://www.appcoda.com"]];
    //    [controllerSLC addImage:[UIImage imageNamed:@"test.jpg"]];
    [self presentViewController:controllerSLC animated:YES completion:Nil];

}

Thanks in advance.

¿Fue útil?

Solución

I solved it myself.You have to set its completion using following code.

Just add following code after presenting controller

[controllerSLC setCompletionHandler:^
 (SLComposeViewControllerResult result) {

     [[NSNotificationCenter defaultCenter]postNotificationName:@"hideNotification" object:nil];

     NSString *output = [[NSString alloc] init];


     switch (result) {
         case SLComposeViewControllerResultCancelled:
             output = @"Post Cancelled";
             break;
         case SLComposeViewControllerResultDone:
             output = @"Posted successfully";
             break;

         default:
             break;
     }
 }];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top