dismissviewcontroller崩溃应用后的PushModalAsync

时间:2019-05-12 19:56:20

标签: c# ios xamarin

我正在使用Xamarin Auth通过Google连接。身份验证完成后,我可以这样做:

UIViewController.DismissViewController(true, null);

然后,我单击一个按钮,然后尝试进行pushmodalasync:

await Application.Current.MainPage.Navigation.PushModalAsync(navigationPage)

当我这样做时,我的应用程序因以下异常而崩溃:

  

System.ObjectDisposedException:无法访问已处置的对象。   对象名称:“ PlatformRenderer”。在   Foundation.NSObject.get_SuperHandle()[0x0004a]在   /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS/Foundation/NSObject2.cs:456   在UIKit.UIViewController.get_View()[0x0002a]中   /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS/UIKit/UIViewController.g.cs:2983   在Xamarin.Forms.Platform.iOS.Platform.EndEditing()[0x00051]中   <7402bf39df944a9ebf61606e5f9c45a4>:0 at   Xamarin.Forms.Platform.iOS.Platform.Xamarin.Forms.INavigation.PushModalAsync   (Xamarin.Forms.Page模式,System.Boolean动画)在[0x00000]中   <7402bf39df944a9ebf61606e5f9c45a4>:0 at   Xamarin.Forms.Internals.NavigationProxy.OnPushModal   (Xamarin.Forms.Page模式,System.Boolean动画)在[0x00022]中   D:\ a \ 1 \ s \ Xamarin.Forms.Core \ NavigationProxy.cs:212在   Xamarin.Forms.Application + NavigationImpl。<> n__1(Xamarin.Forms.Page   模态,System.Boolean动画)<0x103c59040 + 0x0004b>在   <209f66ed8fe04cb6a815feb8c3b62471#9e100c547031591382a60437c9f2f5db>:0   在Xamarin.Forms.Application + NavigationImpl + d__3.MoveNext   ()[0x00065]

如果我不这样做

UIViewController.DismissViewController(true, null);

我的应用程序不会崩溃。

这是iOS中与google连接的整页代码:

public class GoogleLoginPageIos : IGoogleLoginPage
  {
    public static GoogleAuthenticator m_auth;
    private static UIViewController viewController;

    public void OnAuthenticationCompleted()
    {
      viewController.DismissViewController(true, null);
    }

    public void OnAuthenticationCanceled()
    {
      viewController.DismissViewController(true, null);
    }

    public void OnAuthenticationFailed()
    {
      viewController.DismissViewController(true, null);
    }

    public void StartAuthentication(Action onStartLogin, Action<Account> onSuccessfullLogin)
    {
      m_auth = new GoogleAuthenticator(onStartLogin, onSuccessfullLogin, this);

      var authenticator = m_auth.OAuth2Authenticator;
      var mainViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
      viewController = authenticator.GetUI();

      mainViewController.PresentViewController(viewController, true, null);
    }
  }

我正在使用选项卡式页面。

有人可以帮我吗?

谢谢

0 个答案:

没有答案