Auto logout after 24 hours

bootsybootsy Member ✭✭
edited April 11 in Xamarin.iOS

Can someone help please with the code below. I added code to App.xaml.cs on the OnStart and when testing it kicks me out of the application after logging in at about 5 seconds. I want to make sure there is nothing wrong with my code that could be causing this to happen. I think it is the Device.StartTimer(TimeSpan.FromSeconds(60), () =>. Should that be Device.StartTimer(TimeSpan.FromHours(24), () => Here is my latest code:

    protected override void OnStart()
         {
             // Handle when your app starts
               _sessionStart = DateTime.Now;

        Device.StartTimer(TimeSpan.FromSeconds(60), () =>
        {
            DateTime lastTimeUsed = default(DateTime);
            // Check if 24 hours has elapsed
            if ((DateTime.Now - lastTimeUsed).TotalHours > 24)
            {
                //logout
                MainPage = new NavigationPage(new LoginPage());
            }

            return true; // True = Repeat again, False = Stop the timer
        });
Tagged:

Posts

Sign In or Register to comment.