Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在keyWindow的rootVC上通过presentViewController跳转的视图中,调用授权接口提示Warning: Attempt to present <UINavigationController #52

Closed
lwsitachi opened this issue Dec 8, 2014 · 17 comments

Comments

@lwsitachi
Copy link

错误场景:
A(视图控制器)通过presentViewController跳转到了B(视图控制器)中,然后在B的按钮事件中调用了授权接口。无法实现跳转,并且出现的错误提示如下:

Warning: Attempt to present <UINavigationController: 0xa8ad560> on <ViewController: 0xa53afb0> whose view is not in the window hierarchy!

自己猜测原因大概是微博的sdk中,先通过keyWindow的rootVC的继承关系获得“根视图”。再通过presentViewController跳转到授权页面。
大概是类似这样吧:
[[SomeInstance getRootViewController] presentViewController:authorVC animated:YES completion:nil];

请相关技术人员帮忙看下:
这边的获取跳转到授权页面的源视图的方法即getRootViewController,是否应该做相应的修改。
或者说,如果我已经通过presentViewController跳转到了自己的某个视图控制器中,如何在这个控制器中调用授权接口吧。

@joshuafeldman
Copy link

I am experiencing this issue as well. It seems like if a modal is presenting authorization does not work

@Mfk759853063
Copy link

我也遇到了从a present 到b,在b 调用授权接口,也是出现这个错误

@haitaoli
Copy link

Same issue here. Version 2.5.1 works fine. The fix will look like this:

UIViewController * topViewController = window.rootViewController;

while (topViewController.presentingViewController)
topViewController = topViewController.presentingViewController;

@keeploading
Copy link

3.0.1版本里还有这个问题,能否赶紧解决这个问题,等着release。

@dannion
Copy link
Collaborator

dannion commented Jan 30, 2015

谢谢反馈,这个问题会在3.1.0版本中修复。3.1.0版本应该在3月份上旬前后发布。

@tmkjchen
Copy link

3.1.0何时发啊。我们也碰到同样的问题了。等着发布呢。谢谢。

@joshuafeldman
Copy link

Any update on when this will be fixed?

@doggy
Copy link

doggy commented Mar 24, 2015

Have you guys forget to release new version in early march?

@joshuafeldman
Copy link

Would love to see a fix for this since currently I am using method swizzling to fix the issue myself

@doggy
Copy link

doggy commented May 6, 2015

@joshuafeldman Which function name did you swizzling on?

@joshuafeldman
Copy link

I made a category on UIViewController and swizzled the presentation method. My code is below although some of the methods are categories I have made on other classes but you get the idea. It isn't my favorite solution and hopefully it will be fixed so I can remove it.

@implementation UIViewController (FGSinaWeiboPresenterFix)

#pragma mark - NSObject Class Methods

+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        /* strongify:ignore */
        [self swizzleInstanceMethod:@selector(presentViewController:animated:completion:)
                           toMethod:@selector(_weibo_fix_presentViewController:animated:completion:)];
    });
}

#pragma mark - Private Methods

- (void)_weibo_fix_presentViewController:(UIViewController *)viewControllerToPresent
                                animated:(BOOL)flag
                              completion:(void (^)(void))completion
{
    // determine if the class name prefix is for the weibo SDK and be safe to make sure the length
    NSString * weiboSDKPrefix = @"WBSDK";
    NSString * className = [self classNameFromViewControllerToPresent:viewControllerToPresent];
    if ( className.length >= weiboSDKPrefix.length ) {
        NSString * prefix = [[className substringWithRange:NSMakeRange(0, weiboSDKPrefix.length)] uppercaseString];
        if ( [prefix isEqualToString:weiboSDKPrefix] ) {
            [[UIViewController topViewController] _weibo_fix_presentViewController:viewControllerToPresent
                                                                          animated:flag
                                                                        completion:completion];
            return;
        }
    }

    // call the original method
    [self _weibo_fix_presentViewController:viewControllerToPresent animated:flag completion:completion];
}

- (NSString *)classNameFromViewControllerToPresent:(UIViewController *)viewController
{
    if ( [viewController isKindOfClass:[UINavigationController class]] ) {
        return [self classNameFromViewControllerToPresent:((UINavigationController *)viewController).topViewController];
    }
    return NSStringFromClass([viewController class]);
}

@doggy
Copy link

doggy commented May 7, 2015

Most appreciate @joshuafeldman

@manymingge
Copy link

still not updated?

@phnessu4
Copy link

微博果然还是黄了,作为一个前微博员工,对这个更新速度和效率,感到一点也不意外。。。
自己动手,丰衣足食。

@SeanChense
Copy link

same with @joshuafeldman .

Presented to a, then use sdk to request token but failed.

@SeanChense
Copy link

@sinaweibosdk This issue should close.

@wujianbotju
Copy link

作为一个前微博员工,感到丢脸,为什么这个bug到现在都还没有修复,我去...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests