我用WinDev Mobile开发,它生成一个项目,然后使用XCode打开该项目进行编译。
仅在WM上尚未开发Facebook上的共享功能,我必须在ObjC中进行开发

我从代码开始:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    SLComposeViewController *controllerSLC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook] ;
    [controllerSLC setInitialText:myMessage];
    [controllerSLC addURL:[NSURL URLWithString:myUrl]];
    [controllerSLC addImage:[UIImage imageNamed:myImage]];

    // NSLog (@"% @", [UIApplication sharedApplication] keyWindow.rootViewController.)

    [self presentViewController:controllerSLC animated:YES completion:Nil];

    controllerSLC.completionHandler = ^(SLComposeViewControllerResult result) {
        NSString *output = nil;
        switch(result) {
            SLComposeViewControllerResultDone box:
                output = @ "Your tweet has-been sent" ;
                status = 2;
                // NSLog (@" SENT ");
                break;
            SLComposeViewControllerResultCancelled box:
                output = @"Your tweet has-been canceled ";
                status = 3;
                // NSLog (@" canceled ");
                break;
            default:
                break;
        }
        [controllerSLC dismissViewControllerAnimated:YES completion:nil] ;
    };

}

我只有一个错误:
Warning Attempt to present <SLComposeViewController > on <CFenPrincipaleViewController> Whose view is not in the window hierarchy !

我添加了代码:
UIViewController *activeController = [UIApplication sharedApplication] keyWindow.rootViewController. ;
if ([ activeController isKindOfClass:[UINavigationController class]]) {
    activeController = [(UINavigationController *)activeController visibleViewController] ;
}
[activeController presentViewController:controllerSLC animated:YES completion:Nil];

它可以在window home应用程序上工作,我没有错误。

但是当我在另一个窗口上调用相同的函数时,错误返回...。
预先感谢您的帮助

最佳答案

我遇到了同样的问题...试一试!

首先获取根视图控制器。

-(UIViewController*) getRootViewController {
return [UIApplication sharedApplication].keyWindow.rootViewController;
}

现在代替activeController = [(UINavigationController *)activeController visibleViewController] ;
做这个:
UIViewController* activeController = [self getRootViewController];

现在,您的最后一行[activeController presentViewController:controllerSLC animated:YES completion:Nil];应该可以了。

希望这可以帮助。

10-08 17:59