alok srivastava
alok srivastava

Reputation: 761

Posting via SLComposeViewController on facebook and twitter in IOS-8

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

Upvotes: 4

Views: 3702

Answers (3)

Franco Facondini
Franco Facondini

Reputation: 1

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

Upvotes: 0

Hitesh Vaghela
Hitesh Vaghela

Reputation: 1635

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];

        });

Upvotes: 0

alok srivastava
alok srivastava

Reputation: 761

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

Upvotes: 1

Related Questions