如何关闭FBWebDialogs [英] How to dismiss FBWebDialogs
问题描述
如何以编程方式关闭FBWebDialogs-我已经看完了所有文档和堆栈溢出问题,似乎没有办法做到这一点?那不可能吗?
How can I dismiss an FBWebDialogs programmatically - I have seen through all the documentation and stack overflow questions, and there seems to be no way to do this? That can't be?
推荐答案
所以我发现了一种方法,该代码将以编程方式触发关闭按钮TouchUpInside,从而关闭对话框,就像有人手动按下关闭按钮一样按钮-它通过遍历应用程序视图层次结构中的最后一个窗口,然后尝试找到FBDialog的关闭按钮而起作用-在我的测试中可以使用,但可能不适用于所有人,这是代码,但实际上Facebook应该向其中添加API调用在他们的SDK中进行操作.
So I found a kind of hacky way to do it, this code will programmatically trigger the close button TouchUpInside thus closing the dialog as if someone had manually pressed the close button - it works by looping through the last window in the app's view hiearachy and then trying to locate the FBDialog's closebutton - it works in my test, but might not work for everyone, here's the code, but really facebook should add an API call to do it in their SDK.
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *fbDialogWrapper = [window.subviews lastObject];
NSLog(@"Class: %@", [[fbDialogWrapper.subviews firstObject] class]);
if ([[fbDialogWrapper.subviews firstObject] isKindOfClass:NSClassFromString(@"FBDialog")]) {
for (UIView *view in ((UIView *)[fbDialogWrapper.subviews firstObject]).subviews) {
if ([view isKindOfClass:[UIButton class]]) {
UIButton *closeButton = (UIButton *)view;
[closeButton sendActionsForControlEvents:UIControlEventTouchUpInside];
NSLog(@"Trigger facebook close");
break;
}
}
}
这篇关于如何关闭FBWebDialogs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!