Xamarin forms: Check if user inactive after some time log out app

前端 未结 4 671
梦毁少年i
梦毁少年i 2021-01-12 01:39

Hi I am trying to build an application in xamarin forms using PCL. I am trying to logout user from my app if the app is idle more than 10minute or more. I tried it by events

4条回答
  •  情歌与酒
    2021-01-12 02:06

    Unfortunately this is not really something that you can easily do on the client side. There is also no way to do it just from the PCL. There might be a plugin that you can add to your project, but I have not found one yet.

    The reason for this is the difference in the way that iOS and Android handle the app life cycle. Both are very different. For instance once iOS suspends your application, there is really only 2 ways to wake it up. GPS location update and Push notification. In Android it is easier as they have the AlarmManager that you can register and intent with to do the logout for you.

    My suggestion would be, if you control the api you are using, have the session expire server side so that any request that comes in after that 10 minutes would fail, and handle those failures appropriately on the client side.

    If your concern is purely for when the app is in the foreground and active but not used, you will then have to implement a timer, and reset it every time there is some user interaction.

提交回复
热议问题