4

I have tried to post on facebook and twitter using SLComposeViewController. my code is

 -(void)postToFacebookWithObject:(id)object FromController:(UIViewController*)vc {

   if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultCancelled)
        {
            DLog(@"Cancelled");

        }
        else
        {
            DLog(@"Done");
        }
        [controller dismissViewControllerAnimated:YES completion:Nil];
    };
    controller.completionHandler =myBlock;
    [controller removeAllImages];
    [controller removeAllURLs];
    NSMutableDictionary *item = (NSMutableDictionary *)object;
    [controller setInitialText:[item objectForKey:@"DealTitle"]];
    if([item objectForKey:@"DealImage"])
      [controller addImage:[item objectForKey:@"DealImage"]];
    if([item objectForKey:@"url"])
    [controller addURL:[NSURL URLWithString:[item objectForKey:@"url"]]];

    [vc presentViewController:controller animated:YES completion:Nil];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:LocStr(@"NO_FACEBOOK_ACCOUNT_CONFIGURED") delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alert show];
    DLog(@"UnAvailable");
}

}

this working fine in ios 7 but in ios 8 this sheet coming behind my view which i have added on window. How i can fix this?enter image description here

alok srivastava
  • 761
  • 8
  • 19

3 Answers3

1

I have solve this issue by adding my view on navigationcontroller.view not on window.

alok srivastava
  • 761
  • 8
  • 19
0
UINavigationController *forShare = [[UINavigationController alloc] initWithRootViewController:vc];
[forShare setNavigationBarHidden:YES];
[self presentViewController:forShare animated:NO completion:nil];

if animated:YES it doesn't works if animated:NO it works for me

Sport
  • 8,570
  • 6
  • 46
  • 65
0
I have resolved through open present-view controller in navigation-bar.it may help you.

SLComposeViewController *controller = [SLComposeViewController   composeViewControllerForServiceType:SLServiceTypeFacebook];
        [controller setInitialText:shareFrom];
        [controller addImage:self.photoImageView.image];
        [controller addURL:[NSURL URLWithString:dayCareWebsite]];
        dispatch_async(dispatch_get_main_queue(), ^ {

            [self.navigationController presentViewController:controller animated:YES completion:nil];

        });
Hitesh Vaghela
  • 1,635
  • 1
  • 11
  • 11