无法在Xamarin iOS中获取RootViewController [英] Unable to get RootViewController in Xamarin iOS

查看:76
本文介绍了无法在Xamarin iOS中获取RootViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了应用,该应用使用Azure AD进行身份验证

I created app, which Authenticate using Azure AD

在Android中可以正常工作,但在iOS中,需要RootViewController才能加载页面.但是UIApplication.SharedApplication.KeyWindow为空.所以我无法获得UIApplication.SharedApplication.KeyWindow.RootViewController

In Android it is working fine, but in iOS, it need RootViewController for load the page. But UIApplication.SharedApplication.KeyWindow is null. So I am not able to get UIApplication.SharedApplication.KeyWindow.RootViewController

下面是代码:

var authResult = await authContext.AcquireTokenAsync(
    graphResourceUri, 
    ApplicationID, 
    new Uri(returnUri), 
    new PlatformParameters(UIApplication.SharedApplication.KeyWindow.RootViewController)
);

通过其他任何方式可以获取RootViewController

Any other way from which I can get RootViewController

推荐答案

这看起来很愚蠢,但可以.

This looks stupid but works.

        UIWindow window = UIApplication.SharedApplication.KeyWindow;
        UIViewController presentedVC = window.RootViewController;
        while (presentedVC.PresentedViewController != null)
        {
            presentedVC = presentedVC.PresentedViewController;
        }

这篇关于无法在Xamarin iOS中获取RootViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆