diff options
author | Poq Xert <poqxert@poqxert.ru> | 2020-07-22 11:35:50 +1000 |
---|---|---|
committer | Poq Xert <poqxert@poqxert.ru> | 2020-07-27 12:18:57 +1000 |
commit | 22f1cf5d73dc3b928425aec063969d1d26f182fa (patch) | |
tree | 66f813149a7bc4b80b68b6a04717df8bc2d3e5f7 /platform/iphone/game_center.mm | |
parent | 0a7942f4bb61cba8f02f2cbe0ec83b95eefa6726 (diff) | |
download | redot-engine-22f1cf5d73dc3b928425aec063969d1d26f182fa.tar.gz |
iOS GameCenter: Add authenticate method
And no longer connect automatically.
Diffstat (limited to 'platform/iphone/game_center.mm')
-rw-r--r-- | platform/iphone/game_center.mm | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm index 4481775c32..b237ba6bb6 100644 --- a/platform/iphone/game_center.mm +++ b/platform/iphone/game_center.mm @@ -52,6 +52,7 @@ extern "C" { GameCenter *GameCenter::instance = NULL; void GameCenter::_bind_methods() { + ClassDB::bind_method(D_METHOD("authenticate"), &GameCenter::authenticate); ClassDB::bind_method(D_METHOD("is_authenticated"), &GameCenter::is_authenticated); ClassDB::bind_method(D_METHOD("post_score"), &GameCenter::post_score); @@ -66,34 +67,17 @@ void GameCenter::_bind_methods() { ClassDB::bind_method(D_METHOD("pop_pending_event"), &GameCenter::pop_pending_event); }; -void GameCenter::return_connect_error(const char *p_error_description) { - authenticated = false; - Dictionary ret; - ret["type"] = "authentication"; - ret["result"] = "error"; - ret["error_code"] = 0; - ret["error_description"] = p_error_description; - pending_events.push_back(ret); -} - -void GameCenter::connect() { +Error GameCenter::authenticate() { //if this class isn't available, game center isn't implemented if ((NSClassFromString(@"GKLocalPlayer")) == nil) { - return_connect_error("GameCenter not available"); - return; + return ERR_UNAVAILABLE; } GKLocalPlayer *player = [GKLocalPlayer localPlayer]; - if (![player respondsToSelector:@selector(authenticateHandler)]) { - return_connect_error("GameCenter doesn't respond to 'authenticateHandler'"); - return; - } + ERR_FAIL_COND_V(![player respondsToSelector:@selector(authenticateHandler)], ERR_UNAVAILABLE); ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController; - if (!root_controller) { - return_connect_error("Window doesn't have root ViewController"); - return; - } + ERR_FAIL_COND_V(!root_controller, FAILED); // This handler is called several times. First when the view needs to be shown, then again // after the view is cancelled or the user logs in. Or if the user's already logged in, it's @@ -126,6 +110,8 @@ void GameCenter::connect() { pending_events.push_back(ret); }; }); + + return OK; }; bool GameCenter::is_authenticated() { |