Skip to content

registerWrappedClientWithGameHandle:clientDelegate

注册游戏包装客户端代理

该方法用于将宿主应用的代理实现与特定的游戏句柄绑定。通过此接口,SDK 可以向宿主应用请求必要的交互实现(如 UI 展示、特定业务逻辑回调等)。


方法声明

objectivec
/**
 * Sets the delegate client to handle required callbacks and interface
 * implementations from the SDK to the host application.
 */
+ (void)registerWrappedClientWithGameHandle:(nonnull id<SUDRTGameHandle>)gameHandle
                             clientDelegate:(nonnull id<SUDOPWrappedClientDelegate>)clientDelegate;

参数说明

参数名类型必传描述
gameHandleid<SUDRTGameHandle>startGame 成功回调返回的游戏实例句柄。
clientDelegateid<SUDOPWrappedClientDelegate>宿主应用实现的代理对象,需遵循 SUDOPWrappedClientDelegate 协议。

运行行为

  1. 绑定逻辑:SDK 内部会维护 gameHandleclientDelegate 的映射关系。
  2. 生命周期同步:当游戏运行过程中需要触发宿主功能(如弹出登录框、分享、请求支付等)时,将通过此代理回调。
  3. 自动覆盖:如果对同一个 gameHandle 多次调用此方法,后注册的 clientDelegate 将覆盖之前的。

代码示例

objectivec
// 假设已在 startGame 回调中拿到 gameHandle
[SUDOP registerWrappedClientWithGameHandle:gameHandle 
                            clientDelegate:self];

注意事项

  • 调用时机:建议在 startGameonCreated 回调中立即注册,以确保游戏启动初期的交互不会丢失。
  • 内存管理:SDK 内部通常对 clientDelegate 持有强引用弱引用(取决于具体架构设计,建议宿主应用确保 Delegate 在游戏生命周期内不被提前释放)。
  • 清理机制:当调用 stopGame 或游戏销毁时,建议 SDK 内部自动解绑该代理,以防止循环引用或野指针。