gameNetwork.init()

Type Function
Library gameNetwork.*
Return value none
Revision Release 2022.3683
Keywords gameNetwork, Game Center
See also gameNetwork.request()
gameNetwork.show()

Overview

Initializes an app for use with Game Center.

Important

If using/testing Game Center on iOS 8.x and Xcode 6+, you must enable the Game Center sandbox by opening the Settings app on the device, selecting Game Center and enabling Sandbox.

Syntax

gameNetwork.init( "gamecenter" [, initCallback] )
initCallback (optional)

Listener. Callback function where, upon successful login, event.data will be true. If unsuccessful, event.data will be false. When problems such as network errors occur, event.errorCode (integer) and event.errorMessage (string) will be defined.

Gotchas

Example

local gameNetwork = require( "gameNetwork" )

local loggedIntoGC = false

local function initCallback( event )

    if ( event.type == "showSignIn" ) then
        -- This is an opportunity to pause your game or do other things you might need to do while the Game Center Sign-In controller is up.
    elseif ( event.data ) then
        loggedIntoGC = true
        native.showAlert( "Success!", "", { "OK" } )
    end
end

local function onSystemEvent( event ) 
    if ( event.type == "applicationStart" ) then
        gameNetwork.init( "gamecenter", initCallback )
        return true
    end
end
Runtime:addEventListener( "system", onSystemEvent )