nihalahmed / GameCenterManager

iOS Game Center helper singleton

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Present Login Screen Programmatically

dehli opened this issue · comments

commented

Thanks for this great library! Is it possible to present the login view controller programmatically? I tried using the delegate authenticate user function, but I couldn't figure out what would need to go in the last parameter. Thanks again!

First, you need to setup GCManager:

[[GameCenterManager sharedManager] setupInitialAvailability];
[[GameCenterManager sharedManager] checkGameCenterAvailability];

GCManager will then make an asynchronous call to GameKit to retrieve the login view controller. If the user is not logged in (please note that while testing on the iOS Simulator, GameKit will always prompt you to login - this is not the behavior on an actual device, refer to issue #16) then the gameCenterManager:authenticateUser: method will be called on your delegate. You should implement that method similar to this:

- (void)gameCenterManager:(GameCenterManager *)manager authenticateUser:(UIViewController *)gameCenterLoginController {
    // Do something with the login controller, either present it now (shown below) or store it to present later
    [self presentViewController:gameCenterLoginController animated:YES completion:nil];
}

From your comment it seems (and correct me if I am wrong), that you do not have a good understanding of delegates / protocols? Take a look at this great tutorial on RyPress, or just do a bit of Googling.

Closing the issue now because this is an answerable question, rather than a project issue.

commented

Thanks a lot! I did have it implemented like that. I was wondering how to present the login if they disregarded the login message initially and then tried to access a GameCenter portion of my app. From what I'm understanding, I could save the view in authenticateUser that I could display later. I thought it would need to be a feature added to the library. Sorry about that.

In my app, I handle it by using the authentication delegate. If the user is unauthenticated and there is no available controller, I prompt them to open the GameCenter app and login. If they don't want to login, then I just hide all GameCenter features until they decide to login.

And yes, you're correct - you could store the login VC for later.

No problem! Glad to help!