Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity: Stay logged in on mobile devices

I am kinda new to Unity. I am currently developing my first game for IOS and Android. I am at the point where I want my users to sign up and log in. I'll store their data inside a mysql database. That works fine. However, I lack some basic knowledge on that procedure for mobile apps in general.

If a user signs up and logs in and closes the app, how do I handle his session? In games like Clash of clans, you basically sign up once and stay logged in forever with your mobile phone even if u delete the app and download it again.

How is that handled inside mobile apps by Unity? In PHP, I would simple use a session and/or cookies to achieve that. But as I said, I lack some basic knowledge on how that is done on mobile games.

Basically, I want to know on how to distinguish players by their IDs and make them sign up once with their phone and stay signed in forever, at least as long as they don't log out. How do I create these sessions?

Any help would be appreciated.

Have a nice day!

like image 851
user2669261 Avatar asked Nov 29 '25 21:11

user2669261


1 Answers

in ios and android, android when you press the home button and ios when you press the circle button it is going to fire

 void OnApplicationPause(bool pauseStatus) {
        paused = pauseStatus;
        //do your sign in and sign out work
    }

when it runs that method in your game and the user is out for a period of time usually the service of being signed in and out will sign out so you have to have a method to check if your service is signed in or not

isSignedIn();

using that in an if{} then you can automatically sign back in or not in the OnApplicationPause() method

for android if they press the back button

if(Input.GetKeyDown(KeyCode.Escape)){}

then that will end your app totally so when they open the app back up it will start from your initial loading screen then you can silently authenticate them into the sign on process, same for ios too if you are using

Application.Quit() 

int your game

like image 192
JRowan Avatar answered Dec 01 '25 18:12

JRowan