我使用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];
这个应用在Windows家庭版上可以正常工作,我没有遇到错误。
但是当我在另一个窗口调用相同的函数时,错误就出现了......
非常感谢您的帮助。
else if (activeController.modalViewController) {activeController = activeController.modalViewController;}
请将其添加。 - Slayes