既定のユーザーをサイレントに取得する方法を示す例
ゲームは、最初のユーザーを確立する必要があります。この例では、これをできるだけ早く達成する方法を示します。通常、ゲームのメニューでユーザーを明確に識別する何かで「あいさつ」したいが、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;
}
