Lifecycle API
Lifecycle API
OnShow(Action<OnShowResult> callback)
应用切换到前台时触发的事件。通过 static event 注册。
回调参数 (OnShowResult):
| 字段 | 类型 | 说明 |
|---|---|---|
query | string | 启动查询参数 |
void OnEnable()
{
TudadaSDK.OnShow += OnAppShow;
}
void OnDisable()
{
TudadaSDK.OnShow -= OnAppShow;
}
void OnAppShow(OnShowResult result)
{
Debug.Log("应用进入前台");
Time.timeScale = 1;
// 播放BGM、恢复游戏等
}
OnHide(Action<OnHideResult> callback)
应用切换到后台时触发的事件。通过 static event 注册。
回调参数 (OnHideResult):
| 字段 | 类型 | 说明 |
|---|---|---|
reason | string | 切换到后台的原因 |
void OnEnable()
{
TudadaSDK.OnHide += OnAppHide;
}
void OnDisable()
{
TudadaSDK.OnHide -= OnAppHide;
}
void OnAppHide(OnHideResult result)
{
Debug.Log("应用进入后台");
Time.timeScale = 0;
// 保存数据、暂停游戏等
}
ExitMiniProgram(onSuccess, onFail)
退出应用。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
onSuccess | Action<ExitMiniProgramResult> | - | 成功回调 |
onFail | Action<string> | - | 失败回调 |
TudadaSDK.Instance.ExitMiniProgram(
onSuccess: (result) => Debug.Log("退出请求已发送")
);
RestartMiniProgram(onSuccess, onFail)
重启应用。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
onSuccess | Action<RestartMiniProgramResult> | - | 成功回调 |
onFail | Action<string> | - | 失败回调 |
TudadaSDK.Instance.RestartMiniProgram(
onSuccess: (result) => Debug.Log("重启请求已发送")
);