> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 处理手柄丢失

> 处理手柄丢失

对于大多数游戏来说,让手柄与用户相关联至关重要。当
游戏丢失某用户的所有此类手柄时(例如,电池没电了),
单人游戏的标准做法是暂停游戏并显示一个对话框,
要求用户开启手柄。

使用 [XUserFindControllerForUserWithUiAsync](/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync)
函数,游戏可以改善这种体验。此函数以 XUserHandle
作为输入,并显示一个对话框:

\<\<Gamer>>,你在此游戏中需要一个手柄。
按住 A 键确认你想使用的手柄

用户确认其手柄后,游戏可以调用
[XUserFindControllerForUserWithUiResult](/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiresult)
获取所选手柄的 APP\_LOCAL\_DEVICE\_ID。更重要的是,该
手柄现在与该用户相关联。如果该用户随后按下 Nexus 键,
XBOX Guide 会在指南中显示该用户的信息。

请注意,玩家可以在不选择手柄的情况下取消此对话框,游戏应妥善处理这种取消。例如,游戏可以反复调用 [XUserFindControllerForUserWithUiAsync](/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync) 以强制选择,或者由于不再有用户/手柄映射而返回到游戏标题界面,或者采取适合该游戏的其他行为。

另请注意,在这一过程中,用户可以关联到之前与游戏中其他用户关联的手柄。这是有意为之的。

任何时候用户与手柄之间的关联发生变化,都会触发
[XUserDeviceAssociationChangedCallback](/reference/system/xuser/functions/xuserdeviceassociationchangedcallback)。
注意,由调用 [XUserFindControllerForUserWithUiAsync](/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync)
成功完成的用户与手柄配对同样会触发此事件。

## 另请参见

[XUserFindControllerForUserWithUiAsync](/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync)


## Related topics

- [用户](/zh-CN/build/core-features/common/user/user-toc.md)
- [示例](/zh-CN/build/core-features/common/game-streaming/building-touch-layouts/samples/index.md)
- [用户与手柄的关联在何时发生?](/zh-CN/build/core-features/common/user/users-timing-of-user-to-device-association.md)
- [处理离线游戏的最佳实践](/zh-CN/services/xbox-services/develop/best-practices/live-best-practices-offline-play.md)
- [XR-074 与 XBOX 和合作伙伴服务的连接丢失](/zh-CN/publishing/certification/xr/xr-074.md)
