3

I am using SLComposeViewController for sharing in Twitter and Facebook in my app. It is working fine for Twitter but for Facebook, SLComposeViewController closes automatically on selecting location. This is an iOS 8 issue. Working fine on iOS7.

 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
            self.fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

            SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

                //  [fbSheet dismissViewControllerAnimated:YES completion:nil];

                switch(result){
                    case SLComposeViewControllerResultCancelled:
                    default:
                    {
                        NSLog(@"Cancelled.....");

                    }
                        break;
                    case SLComposeViewControllerResultDone:
                    {
                        NSLog(@"Posted....");
                        if([NetworkManager SharedInstance].isInternetReachable){
                        UIAlertView *alertView = [[UIAlertView alloc]
                                                  initWithTitle:@"Success"
                                                  message:@"Feeds shared successfully."
                                                  delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
                        [alertView show];
                        }

                    }
                        break;
                }};


            [self.fbSheet setCompletionHandler:completionHandler];
            NSString *fbString= self.titleString;
            [self.fbSheet setInitialText:fbString];
            [self.fbSheet addURL:[NSURL URLWithString:self.urlString]];
            [self presentViewController:self.fbSheet animated:YES completion:nil];


        }

The control is automatically going into completion handler block with result as cancelled. I have gone through some posts suggesting it is 64 bit architecture problem. Please help me with this if anyone is facing the same issue.

Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
monicak
  • 41
  • 6

1 Answers1

0
  - (IBAction)facebookPost:(id)sender {

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    self.fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [self.fbSheet setInitialText:@"Social Framework test"];

    [self.fbSheet addImage:[UIImage imageNamed:@"imagename.png"]];

    [self.fbSheet addURL:[NSURL URLWithString:@"URL_NAME"]];

    [self.fbSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

         switch (result) {
             case SLComposeViewControllerResultCancelled:
                 NSLog(@"Post Canceled");
                 break;
             case SLComposeViewControllerResultDone:
             {
                 NSLog(@"Post Sucessful");
                NSLog(@"Posted....");
                    if([NetworkManager SharedInstance].isInternetReachable){
                    UIAlertView *alertView = [[UIAlertView alloc]
                                              initWithTitle:@"Success"
                                              message:@"Feeds shared successfully."
                                              delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
                    [alertView show];
                    }
                }
                 break;

             default:
                 break;
         }
     }];

    [self presentViewController:self.fbSheet animated:YES completion:nil];
}
}
Bhoomi Jagani
  • 2,413
  • 18
  • 24