Type Function Library gameNetwork.* Return value none Revision 2017.3060 Keywords gameNetwork, Game Center See also gameNetwork.request() gameNetwork.show()
Initializes an app for use with Game Center.
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.
gameNetwork.init( "gamecenter" [, initCallback] )
The event.type
called "showSignIn"
will be invoked before the Game Center login screen appears. This gives you a chance to pause your game or do any special actions you need before the login view takes over the screen. On successful login, event.data
will return the login status (presumably false
), so code which does not check for this type will still work. When this view is dismissed, the callback will be invoked again with event.type
set to "init"
to handle the results of the login.
Be aware that iOS backgrounding will cause your app to automatically log out the user from Game Center. When the app is resumed, Game Center will automatically try to
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 )