首页 > 解决方案 > 在 SceneDelegate.ContinueUserActivity 中验证用户的模式?

问题描述

我在 Xamarin.iOS 上使用 Deeplinking。

如果用户与我的应用程序断开连接,我找不到处理链接的模式。在这种情况下,我需要在离开 SceneDelegate.ContinueUserActivity 之前等待登录完成时重定向到登录页面,对吗?

到目前为止,我尝试的是在我的登录 ViewController 中设置 Nito.AsyncEx.AsyncAutoResetEvent,然后在AsyncHelpers的帮助下等待它。但是登录用户界面被冻结了。

[Export("scene:continueUserActivity:")]
public void ContinueUserActivity(UIScene scene, NSUserActivity userActivity)
{
    ....
    if (notAuthenticated)
    {
        // The user is not authenticated
        // Redirect to the Login Page

        LoginViewController lvc = new LoginViewController(true);

        if (Window.RootViewController == null)
        {
            var navController = new UINavigationController(lvc);

            Window.RootViewController = navController;
         }
         else
         {
              UINavigationController rootViewController = ((UINavigationController)Window.RootViewController);
              rootViewController.PopToRootViewController(true);
              rootViewController.PushViewController(lvc, true);
          }

          Window.MakeKeyAndVisible();

          AsyncHelpers.RunSync(async() => await lvc.LoginFinishedOrCancelled.WaitAsync());
 
          ...
    }
}

据我所知,没有办法让 ContinueUserActivity 异步感知。

标签: c#iosxamarin.ios

解决方案


AsyncHelpers.RunSync(async() => await lvc.LoginFinishedOrCancelled.WaitAsync());您可以在登录页面而不是 SceneDelegate 中调用该行。


public bool isNeedLoad {get;set;}

public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
             
            if(isNeedLoad)
            {
               // ...AsyncHelpers.RunSync(async() => await lvc.LoginFinishedOrCancelled.WaitAsync());
              isNeedLoad = false ;
            }
            
           
        }
LoginViewController lvc = new LoginViewController(true){isNeedLoad  = true};

        if (Window.RootViewController == null)
        {
            var navController = new UINavigationController(lvc);

            Window.RootViewController = navController;
            Window.MakeKeyAndVisible();
         }
         else
         {
              UINavigationController rootViewController = ((UINavigationController)Window.RootViewController);
              rootViewController.PopToRootViewController(true);
              rootViewController.PushViewController(lvc, true);
          }

          

推荐阅读