Message:

Subscribe rss
Blog categories
All | Backendless features
How to Develop a Multi-User Game for iOS
March 19, 2019 by Olga Danilova

For this series, we are developing an iOS game called “TapMe”. As TapMe is a multiplayer game, it provides registration for the new users and login for the existing ones. In this article, we are going to demonstrate how to handle user registration and login, as well as how to store a player’s information in the database.

The source code for the game is available in the author’s personal Github repo: https://github.com/olgadanylova/TapMe.git

You can read Part 1 of this series here.

Develop an iPhone Game App

First, it is necessary to insert the existing APP_ID and API_KEY values into the AppDelegate.m class; otherwise, when the first-time user tries to sign up or login, he or she will receive the “KEY before running the app. Closed” error and the app will close.

AlertViewController.swift

Login configuration error

New Player Registration

The registration screen appears after pressing the “Sign up” button on the main screen. The user can set his/her profile picture, name, email address, and password.

Sign in screen

After pressing the “Sign up” button, registration is complete and the user will be automatically signed in to start a game.

During the registration process, a new player based on the BackendlessUser  is created. The profile picture is uploaded using the FileService API to the Backendless server and is stored in the tapMeProfileImages  folder.

We will use the snippets of code below to complete the new player registration process:

Player.swift

 

The next section of code describes:

  1. Picture uploading to a server
  2. New BackendlessUser registration (if he/she doesnt exist)
  3. Creation of the new player based on the BackendlessUser from step 2 with a 1:1 relationship.

RegisterViewController.swift

AlertViewController.swift

 

Some errors could appear while registering a new player. If you encounter any of these errors, you can look up solutions here: https://backendless.com/docs/ios/doc.html#user-registration

Existing Player Login

The player should enter his/her login and password to sign in.

Sign up screen

Some errors could appear while signing in. You can see more detail about those errors here: https://backendless.com/docs/ios/users_login.html#errors

Our “TapMe” app is designed to remember the logged in player and login will occur automatically after the app restart. If the player signs in on another device, the first device will be logged out and show the login screen when the app restarts.

LoginViewController.swift

These are the steps of the login method:

  1. Checking if player exists
  2. If the player exists, he/she is logged in and the game starts
  3. If the player doesn’t exist, a message asking them to register appears

 

AlertViewController.swift

 

That’s all for now. Next time, I’ll show you how to calculate and display the players on a leaderboard. Happy building!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+