问题
I have a problem with this login scenario in current game project:
- User logs in using their account details (previously registered PFUser on Parse backend)
- They play the game for a while, then leave the game (still logged in)
- They log in on another device and play
I would like to somehow log the other device out since there shouldn't be TWO or more logged in devices AT THE SAME time because it's a multiplayer game.
How can I detect whether the user is logged in somewhere else? What is the best approach to handle same user logged in in many places? I want to prevent overwriting data and inconsistency. Thanks in advance.
回答1:
You can generate a unique identifier for each installation of your game (just a UUID stored in user defaults). Each time a use logs in, update the identifier into your user information stored on the server. When you upload any edit to the server you can send the identifier and check it with cloud code (or check the identifier first) to decide if the login is still valid. How you check depends on what you want to do if you find the login to be invalid. The more efficient route is to use cloud code and send back an error response that the app handles to alert the user and action the logout.
来源:https://stackoverflow.com/questions/17905911/handling-login-on-multiple-devices-using-parse-ios