자동으로 기본 사용자를 가져오는 방법 예제
게임은 초기 사용자를 설정해야 합니다. 이 예제는 가능한 한 빨리 이를 달성하는 방법을 보여줍니다. 게임 메뉴가 사용자를 명확하게 식별하는 것으로 “환영”하려는 경우 그리고 UI를 즉시 표시하고 싶지 않은 경우 일반적으로 이 패턴을 따르는 것이 좋습니다.HRESULT Identity_TrySignInDefaultUserSilently(_In_ XTaskQueueHandle asyncQueue)
{
XAsyncBlock* asyncBlock = new XAsyncBlock();
asyncBlock->queue = asyncQueue;
asyncBlock->callback = Identity_TrySignInDefaultUserSilently_Callback;
// Request to silently sign in the default user.
HRESULT hr = XUserAddAsync(XUserAddOptions::AddDefaultUserSilently, asyncBlock);
if (FAILED(hr))
{
delete asyncBlock;
}
return hr;
}
void CALLBACK Identity_TrySignInDefaultUserSilently_Callback(_In_ XAsyncBlock* asyncBlock)
{
// NOTE: XUserAddResult will add a Ref to the passed-in XUserHandle.
XUserHandle newUser = nullptr;
HRESULT hr = XUserAddResult(asyncBlock, &newUser);
if (SUCCEEDED(hr))
{
// TO DO: create Xbox services context and do something with that user.
// ...
}
else
{
// You are here because there's no default user or because of an error.
// Display some UI, such as "Press A or Enter to continue," and try the sign-in with the UI flow.
}
delete asyncBlock;
}
초기 사용자를 얻는 방법 예제
이전 예제와 마찬가지로, 게임은 초기 사용자를 설정해야 합니다. 이 경우 게임은 사용자를 요청할 때 UI가 표시되도록 허용합니다. 시스템이 기본 사용자를 결정할 수 없는 경우에만 UI가 표시됩니다.HRESULT Identity_TrySignInDefaultUser(_In_ XTaskQueueHandle asyncQueue)
{
XAsyncBlock* asyncBlock = new XAsyncBlock();
asyncBlock->queue = asyncQueue;
asyncBlock->callback = Identity_TrySignInDefaultUser_Callback;
// Request to silently sign in the default user.
HRESULT hr = XUserAddAsync(XUserAddOptions::AddDefaultUserAllowingUI, asyncBlock);
if (FAILED(hr))
{
delete asyncBlock;
}
return hr;
}
void CALLBACK Identity_TrySignInDefaultUser_Callback(_In_ XAsyncBlock* asyncBlock)
{
// NOTE: XUserAddResult will add a Ref to the passed-in XUserHandle.
XUserHandle newUser = nullptr;
HRESULT hr = XUserAddResult(asyncBlock, &newUser);
if (SUCCEEDED(hr))
{
// TO DO: create Xbox services context and do something with that user.
// ...
}
else
{
// You are probably here because someone canceled out of the UI flow to
// sign in or an expected error occurred.
// Display some UI, such as "Press A or Enter to continue," and try the sign-in
// again with the UI flow.
}
delete asyncBlock;
}
