Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ISSUE-015

Game Center登录界面不显示

常见表现

游戏加载时卡住,游戏登录过程卡住。

原因分析

游戏与Game Center登录强绑定,需要等Game Center登录API -[GKLocalPlayer setAuthenticateHandler:]返回结果后才会继续下一步。

但由于签名限制,PlayCover中的应用是无法拉起Game Center登录界面的,Game Center登录API也不会有任何反应,甚至不会通过回调函数返回错误信息。

解决方法

方法一:禁用SIP并修改boot-args,可正常显示Game Center登录界面。

方法二:伪造一个用户已取消操作的Game Center登录结果。

PlayTools NSObject+Swizzle.m

#import <GameKit/GameKit.h>

- (void) hook_setAuthenticateHandler:(void (^)(UIViewController *, NSError *))handler {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        NSError *error = [NSError errorWithDomain:GKErrorDomain
                                             code:GKErrorCancelled
                                         userInfo:@{
            NSLocalizedDescriptionKey: @"The requested operation has been cancelled or disabled by the user."
        }];
        if (handler != nil) {
            handler(nil, error);
        }
    });
}

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
	[objc_getClass("GKLocalPlayer") swizzleInstanceMethod:@selector(setAuthenticateHandler:) withMethod:@selector(hook_setAuthenticateHandler:)];
});