我的目標是在空閑超時后將用戶重定向回登錄屏幕。每次點擊/觸摸后,我都有這段代碼進行倒計時。它運行良好,但我目前的問題是我不知道將用戶重定向回登錄屏幕。由于這是 MvvmCross 4.4 項目,因此沒有太多文檔可供查找。如果我也可以獲得 Android 的示例代碼,那將非常有幫助。我會感激的。下面是我放在 Main.cs 中的代碼public class Application{ static void Main(string[] args){ //UIApplication.Main(args, null, "AppDelegate"); UIApplication.Main(args, "MyApplication", "AppDelegate"); } } //DELEGATE [Register("MyApplication")] public class MyApplication : UIApplication { public override void SendEvent(UIEvent uievent) { base.SendEvent(uievent); var allTouches = uievent.AllTouches; if (allTouches.Count > 0) { var phase = ((UITouch)allTouches.AnyObject).Phase; if (phase == UITouchPhase.Began || phase == UITouchPhase.Ended) ResetIdleTimer(); } } NSTimer idleTimer; void ResetIdleTimer() { if (idleTimer != null) { idleTimer.Invalidate(); idleTimer.Dispose(); } idleTimer = NSTimer.CreateScheduledTimer(TimeSpan.FromMinutes(0.5), TimerExceeded); } void TimerExceeded(NSTimer obj) { MvxiOSToastService toastService = new MvxiOSToastService(); toastService.DisplayMessageAndDoSomething("You are going to be timed out.","Idle time exceeded.", RedirectToLogin); Console.WriteLine("idle time exceeded"); } void RedirectToLogin() { var window = UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; //ERROR HERE var nextVC = new LoginView(); vc.ShowViewController(nextVC, this); //---------- } }
如何從 UIApplication Xamarin.iOS 對 Mvx View 進行導航調用
幕布斯6054654
2023-05-14 16:13:00