【Unity】【iOS】 Xcode15.2 导出的应用,GameCenter登录 在iOS17上不可用

2,692 阅读2分钟

最近游戏客户端反应使用Unity原生接入的GameCenter登录,在iOS17系统下不可用。在排查过程中,查漏补缺各种信息点,有了这篇文章。

文章主要讲通过Xcode和Unity配置Game Center Capability的方式、注意事项以及问题的解决方案。

1 配置方式

1.1 通过Xcode配置Game Center Capability

我们需要在Xcode中添加Game Center Capability,添加方式如下:

image-20240510095615447.png

并在App Store Connect 为对应BundleID 配置Game Center Capability,配置方法如下:

image-20240510100140707.png

修改好BunldID配置后,重新导出dev和dis的.mobileprovision文件,并将.mobileprovision文件导入Xcode中。

1.2 通过Unity配置 Game Center Capability:

我们仍旧需要添加Game Center Capability。Unity为我们提供了添加Xcode Capability的管理类:ProjectCapabilityManager,添加Game Center Capability代码为:ProjectCapabilityManager.AddGameCenter()

同样的我们也需要在App Store Connect 为对应BundleID 配置Game Center Capability和.mobileprovision文件,步骤和上面一样,这里不赘述了。

2 注意事项:

2.1 自2023年8月16日,Apple 发布 Game Center 授权和配置要求,内容如下:

image-20240510101223414.png

根据该要求可知,无论iOS原生应用还是Unity开发并上架的iOS应用,在使用GameCenter服务的时候,不仅要配置Game Center Capability,还需要在授权文件(也就是XXX.entitlements文件)中包含key:com.apple.developer.game-center,value:true,详见:Game Center Entitlement.

2、自Xcode14开始,Apple会为新添加Game Center Capability的应用,自动得在XXX.entitlements文件中增加com.apple.developer.game-center,无需程序员手动添加。但在Xcode14之前就已经添加Game Center Capability的应用,XXX.entitlements文件中可能不包含com.apple.developer.game-center信息,我们需要手动检查并添加。更多内容见:Capability and entitlement updates

3、我们遇到的问题是“使用Unity原生接入的GameCenter登录,在iOS17系统下不可用”。

【开发信息】:

  • Unity Editor:2020.3.28f1
  • Xcode:15.2(Xcode14在iOS17上未出现该问题)

【原因】:

1)在2020.3.28f1版本的Unity Editor中,使用ProjectCapabilityManager.AddGameCenter()添加Game Center Capability,并不会自动将com.apple.developer.game-center信息添加到XXX.entitlements文件中。

image.png

2)自Xcode15以来,苹果删除了添加Game Center Capability,就会在XXX.entitlements文件中自动添加com.apple.developer.game-center的功能。详见:Xcode 15 Release Notes

  • Fixed: If your app integrates with Game Center, make sure that the com.apple.developer.game-center entitlement is present in your Entitlements.plist file. Previous Xcode versions automatically injected the entitlement into your app’s signature if it was present in your provisioning profile. That behavior was inconsistent with most other entitlements, and has been removed in Xcode 15. (106596235)

总的来看,就是XXX.entitlements中缺失com.apple.developer.game-center,导致Game Center服务未完全启用,才产生的bug。

【解决方案】:

因为我们Unity开发的iOS项目使用自动化打包,所以通过脚本为权限文件entitlements添加了com.apple.developer.game-center

具体方式见:forum.unity.com/threads/upc…

【补充】:

如果你是Xcode开发的iOS应用,直接在XXX.entitlements文件添加key:com.apple.developer.game-center,value:true 即可。