startGameWithSignature:didGameHandleCreated:completion:
启动游戏(通过游戏签名)
该方法使用授权签名(Game Signature)正式启动游戏。这是生产环境下最推荐的启动方式,因为它通过签名机制确保了游戏的安全校验,并能精确锁定特定版本的资源。如果之前已经通过该签名执行过 preStart 或 preLoad,游戏将实现物理意义上的“秒开”。
方法声明
objectivec
/**
Start the game with a game signature.
@param gameSignature The signature used to authorize the game operation.
@param didGameHandleCreated Called when the game handle is created. Use this to register your delegate.
@param completion Called when the game process has fully started.
@return An instance of id<SUDOPGameTask> to track the startup progress.
*/
+ (id<SUDOPGameTask>)startGameWithSignature:(NSString *)gameSignature
didGameHandleCreated:(nullable SUDOPDidGameHandleCreated)didGameHandleCreated
completion:(nullable SUDOPGameOperationCompletion)completion;参数说明
| 参数名 | 类型 | 必传 | 描述 |
|---|---|---|---|
| gameSignature | NSString * | 是 | 游戏的授权签名字符串(包含 AppID、GameID、用户身份及有效期信息)。 |
| didGameHandleCreated | Block | 否 | 核心回调。当游戏实例创建成功但尚未渲染首帧时触发。此时必须通过 gameHandle 挂载视图。 |
| completion | Block | 否 | 最终回调。表示游戏已经越过加载界面,进入了可玩状态。 |
运行行为
- 状态机检查:SDK 检查是否存在匹配此签名的后台实例(来自
preStart)。
- 命中预热:直接激活该实例,跳过资源解析和环境初始化。
- 未命中预热:执行完整的签名解析 -> 资源下载/校验 -> 环境初始化流程。
- 生命周期切换:游戏从“后台静默”或“未运行”状态切换至“前台活跃”状态。
- 渲染激活:此时调用
[gameHandle getGameView]将返回一个可以被添加到视图层级中的 UIView 实例。
代码示例
objectivec
[SUDOP startGameWithSignature:mySignature
didGameHandleCreated:^(id<SUDRTGameHandle> gameHandle) {
// 1. 绑定业务逻辑代理
[SUDOP registerWrappedClientWithGameHandle:gameHandle clientDelegate:self];
// 2. 将游戏视图呈现给用户
UIView *gameView = [gameHandle getGameView];
gameView.frame = self.containerView.bounds;
[self.containerView addSubview:gameView];
NSLog(@"游戏句柄创建成功,视图已挂载");
}
completion:^(id<SUDOPGameHandleProvider> _Nullable provider, NSError * _Nullable error) {
if (!error) {
NSLog(@"游戏运行中...");
} else {
// 处理签名过期、网络异常或校验失败
NSLog(@"启动失败: %@", error.localizedDescription);
}
}];注意事项
- 句柄唯一性:每个游戏实例对应一个
gameHandle。在游戏退出(stopGame)前,请务必妥善保存该句柄,因为它是与游戏交互(如发送指令、禁言、结算)的唯一入口。 - 内存管理:如果在
didGameHandleCreated中将gameView添加到了self.view,请确保在游戏结束时将其从父视图移除,并调用释放接口。 - 签名时效:该接口会严格校验
gameSignature。如果用户在详情页停留时间过长导致签名过期,调用此方法将返回错误。