GameCenter登录坑点总结

之前接入了GameCenter登录,发现了我遇到的几个坑点,总结一下:
代码调用很简单。但是当我们调用下面代码进行呼出GameCenter弹框进行登录时

GKLocalPlayer * localPlayer = [GKLocalPlayer localPlayer];
[localPlayer setAuthenticateHandler:^(UIViewController * _Nullable viewController, NSError * _Nullable error){
if (viewController) {
                UIViewController * rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
                [rootViewController presentViewController:viewController animated:YES completion:nil];
            } else {
                if ([GKLocalPlayer localPlayer].authenticated) {
                    
                } else {
                    
                }
            } 
} 

会发现:

1:App每次从后台切换到前台都会走上面block回调,这个需要注意,所以现在我做了进入前台监听防止重复调用block里面相关内容
2:如果后台登录了GameCenter账号A,在切换登录了GameCenter账号B,在进入App前台的时候,会走block回调,并且有苹果自带的GameCenter登录成功的弹框。很烦。。
会让用户误以为自己又重新登录GamCenter了呢,其实并没有走我们自己的登录。
3:如果呼出GameCenter弹框进行登录,连续呼出三次都点击了左上角的取消按钮,下次你在登录会发现呼不出来GameCenter弹框了,
模拟器很好测试,如果需要再次呼出需要重置模拟器,可再次呼出,我们现在这块做的逻辑处理是:
当本地GameCenter未登录,且呼不出来GameCenter弹框的时候,就提示用户GameCenter若Game Cen异常,请先在系统设置页登录Game Center后,再登录游戏,
让用户在设置里面登录GameCenter
4:如果登录提示一下错误This game is not recognized by Game Center,对应iTunes后台gameCenter配置问题,设置什么排行榜之类的.可参考

GameCenter登录坑点总结_第1张图片
tmp37fc557a.png

自己遇到了上面的一些坑,最后写完也发现同样也有别人总结比较好的
iOS开发之GameCenter使用

你可能感兴趣的:(GameCenter登录坑点总结)