Search code examples
ios8xcode6slcomposeviewcontrollerios8-share-extension

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


Solution

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