c# - 在 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 异步感知。
解决方案
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);
}
推荐阅读
- python - 带有2个变量的python空格问题
- java - 扩展节点时JavaFX TreeTableView 很慢?
- python - TypeError: object() 没有参数(trex 恐龙机器人)
- php - laravel 5.6 未从 laravel 中的控制器读取变量
- twitter-bootstrap - 在 vue.js 中改变颜色
- android - 共享图像意图在三星 S8 中不起作用
- node.js - npm 请求或 https 模块哪个更好
- grand-central-dispatch - 在 NSDocumentSubclass 初始化期间显示一个窗口
- css - css倾斜元素并获得内部圆角边框顶部
- javascript - 使用 Openseadragon 在大图像上使用 IE 11/Edge 得到“IndexSizeError”