在IOS-8上通过Facebook和Twitter上的SLComposeViewController发布

时间:2014-09-30 07:53:27

标签: ios8 xcode6 slcomposeviewcontroller ios8-share-extension

我试图使用SLComposeViewController在Facebook和Twitter上发帖。我的代码是

 -(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");
}

}

  

这在ios 7中工作得很好,但在ios 8中,这张表在我的视图后面,我在窗口上添加了。我如何解决这个问题?enter image description here

3 个答案:

答案 0 :(得分:1)

我通过在windowcontroller.view上添加我的视图来解决这个问题。

答案 1 :(得分:0)

UINavigationController *forShare = [[UINavigationController alloc] initWithRootViewController:vc];
[forShare setNavigationBarHidden:YES];
[self presentViewController:forShare animated:NO completion:nil];

如果动画:是的,它不起作用 如果动画:不,它对我有用

答案 2 :(得分: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];

        });