iOS GameCenter私有API崩溃:GKNotificationBannerViewController相关问题
GameCenter私有API崩溃问题排查与修复需求
崩溃概况
- 崩溃仅出现在iOS 16.3.1版本的iPhone XR设备上,影响占比不到1%,无法稳定复现
- 崩溃栈指向GameCenter私有API:
GKNotificationBannerViewController::hideBannerQuickly及GKNotificationBannerWindow enqueBanner: - 推测该崩溃与应用启动时自动弹出的「Welcome user_abc」顶部通知横幅有关
现有GameCenter集成实现
我仅在用户点击排行榜按钮时展示GameCenter视图控制器,启动时仅做认证初始化,相关代码如下:
import GameKit public enum GameCenterUtil { private static var g_isEnabled: Bool = false public static func setupIfNeeded() { GKLocalPlayer.local.authenticateHandler = { loginVC, error in if loginVC != nil { // 不主动弹出登录界面,避免打扰用户 return } if error != nil { g_isEnabled = false return } g_isEnabled = true } } public static func reportScore(_ score: Int, category: String) { guard g_isEnabled else { return } GKLeaderboard.submitScore(score, context: 0, player: GKLocalPlayer.local, leaderboardIDs: [category]) { error in // 暂不处理错误 } } public static func presentLeaderboard(in vc: UIViewController) { let gameCenterVC = GKGameCenterViewController() gameCenterVC.gameCenterDelegate = LeaderboardDismisser.shared vc.present(gameCenterVC, animated: true, completion: nil) } } final class LeaderboardDismisser: NSObject, GKGameCenterControllerDelegate { static let shared = LeaderboardDismisser() func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) { // 用户未登录时会弹出提示框,必须手动关闭否则界面无响应 gameCenterViewController.dismiss(animated: true, completion: nil) } }
- 在
didFinishLaunching中调用GameCenterUtil.setupIfNeeded()完成初始化 - 用户点击排行榜按钮时调用
GameCenterUtil.presentLeaderboard(in: vc)展示排行榜
当前修复逻辑与冲突
- 此前为解决「应用后台时GameCenter VC未关闭,前台后VC变透明导致应用无响应」的问题,添加了
sceneDidEnterBackground时自动关闭该VC的逻辑 - 日志确认该自动关闭逻辑与本次私有API崩溃直接相关,尝试延迟1秒关闭仍未解决问题
- 需求:保留后台自动关闭GameCenter VC的修复逻辑,同时解决私有API崩溃问题
内容的提问来源于stack exchange,提问作者OMGPOP
相关产品推荐
相关产品推荐

