How to dismiss FBWebDialogs

你说的曾经没有我的故事 提交于 2020-01-21 20:12:29

问题


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?


回答1:


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;
        }
    }
}



回答2:


Just use [self dismissModalViewControllerAnimated:YES]; it worked well for me!



来源:https://stackoverflow.com/questions/21741101/how-to-dismiss-fbwebdialogs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!