IGameService
public protocol IGameService
The GameService library is meant to manage communication with the Magmic remote v5 Game Service. It manages server configurations, user authentication, Facebook login/logout and manifests. The service uses a GameServiceConfiguration to define how it should communicate with the v5 server. A default configuration is required to be passed in when initializing, other configurations should be defined in the gameService node of the manifest.
When initializing the service it will used the default GameServiceConfiguration passed in until it has successfully connected and received an updated manifest.Once the serviced has a manifest all subsequent calls will be made using the active configuration set in the manifest. If the configuration in the manifest has changed the service will reinitialize it’s connection to the game service using the new configuration set in the manifest.As a safety precaution if this new manifest changes the configuration again initialization will fail to prevent a configuration loop.
-
Returns true if GameService has been successfully initialized. Initizliation requries establishing communicating with the v5 service as well as successfully getting a game’s manifest.
Declaration
Swift
var initialized: Bool -
Preinitialize the Game Service.
Declaration
Swift
func preInitialize() -
Initialize the GameService service.
If there is no saved manifest the default config will be used to make contact with the v5 service. On subsequent initializaiton calls the game service credentials from the saved manifest will be used to make contact with v5. Initialization will asyncronously make contact with the v5 server and retreive a valid manifest for the user. On resolution the user will have a userId and a valid manifest.
Declaration
Swift
func initialize(config: GameServiceConfiguration) -> Promise<Response>Parameters
configA default
GameServiceConfigurationthat is used if there is currenlty no saved configuration.Return Value
A
Promise<Response>, response will be empty on success. -
Initialize service with custom service dependency implementations.
See
initialize(config: GameServiceConfiguration)Custom service implementaitions can be provided which will be used instead of the defaults.
Declaration
Swift
func initialize(manifest: Manifest, darkMatter: IDarkMatter, userService: IUserService, profileManager: IUserServiceProfileManager, usertypes: IUsertypes, networkManager: INetworkManager, defaultConfig: GameServiceConfiguration) -> Promise<Response>Parameters
manifestA default
Manifestthat is used if there is currently no saved configuration.darkMatterA default
IDarkMatterthat is used if there is currenlty no saved configuration.userServiceA default
IUserServicethat is used if there is currenlty no saved configuration.profileManagerA default
IUserServiceProfileManagerthat is used if there is currenlty no saved configuration.usertypesA default
IUsertypesthat is used if there is currenlty no saved configuration.networkManagerdefaultConfigA default
GameServiceConfigurationthat is used if there is currenlty no saved configuration.Return Value
A
Promise<Response>, response will be empty on success. -
Log the current user in as a guest. The users user/guest Id will persist accross logins unless the app is uninstalled, they
logout, or youinvalidateInstallDeclaration
Swift
func loginGuest() -> Promise<Response>Return Value
A
Promise<Response>, response will be empty on success. -
Attempt to login with a user facebook token.
Declaration
Swift
func loginFacebook(token: String?, forceOverwrite: Bool, guestId: String?) -> Promise<Response>Parameters
tokenThe user’s facebook token. On a sucessfull login token will be saved and reused on subsequent loginFacebook requests.
forceOverwriteSet to true if you would like force overwrite any data found for the facebook token user with data from the guest account id provided.
guestIdGuest account id to use data from, should be null / empty if not trying to merge accounts.
Return Value
A
Promise<Response>, response will be empty on success. If an account conflict occurs theDarkMatterErrordata property will have -
Logout the current user, a new guest Id will be generated and all local user data will be reset.
Declaration
Swift
func logout() -> Promise<Response> -
Pass in the userId associated with the account data you’d like to use
Declaration
Swift
func resolveConflictFacebook(userid: String) -> Promise<Response> -
The currently saved facebook token, when set will be saved and reloaded on relaunch.
Declaration
Swift
var facebookToken: String -
The current login status of the current local user.
Declaration
Swift
var loginStatus: GameServiceLoginStatus -
Wipes all data related to the current session NOTE - Install id and facebook token will be preserved.
Declaration
Swift
func invalidateSession() -
Wipes all data related to the current install, this includes installId and facebookToken.
Declaration
Swift
func invalidateInstall() -
Build a dictionary of HTTP header properties that includes a v5 request signature.
Declaration
Swift
func generateHeadersForRequest(request: GameServiceRequest) -> [String: String]Parameters
requestReturn Value
[String: String]containing HTTP header properties. -
Generate a signed hash from a request body.
Declaration
Swift
func generateSignatureHash(config: GameServiceConfiguration, body: String) -> StringParameters
bodyThe stringified body of the request.
-
Declaration
Swift
func hasLoginCredentials() -> BoolReturn Value
true if the currently loaded user information has facebook login credentials.
-
Adds required auth parameters to the request data if needed
Declaration
Swift
func getRequestBodyWithAuthValues(request: GameServiceRequest) -> [String: AnyObject]? -
Get the configuration that maps to the active configuration key
Declaration
Swift
func getActiveConfig() -> GameServiceConfiguration? -
Get the key to the currently active configurations
Declaration
Swift
func getActiveConfigKey() -> String -
Get a dictionary of all configurations currently setup in the Game Service
Declaration
Swift
func getAllConfig() -> [String: GameServiceConfiguration] -
Tracks the number of times the library has failed to initialize / get a new manifest. NOTE - this is mostly for internal library use, but can be queried by the client if needed.
Declaration
Swift
var failedInitAttempts: Int
IGameService Protocol Reference