> ## 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.

# XSAPI C を介したユーザーのプレゼンスの更新

> XblPresenceSetPresenceAsync を使用して XBOX Live ユーザーのオンライン プレゼンス ステータスを更新し、現在のゲーム内アクティビティを広告するフラット C のサンプルです。

このトピックでは、ユーザーのオンライン プレゼンス ステータスを設定するサンプル コードを提供します。XBOX services のリッチ プレゼンスは、プレイヤーの現在のアクティビティを他のプレイヤーに広告するための機能を提供します。

詳細については、「[リッチ プレゼンスの概要](/services/xbox-services/community/presence/live-presence-overview)」を参照してください。

## ユーザーのオンライン プレゼンス ステータスの更新

このサンプル コードは、ユーザーのオンライン プレゼンス ステータスを設定します。

#### フラット C API

```cpp theme={null}
auto asyncBlock = std::make_unique<XAsyncBlock>();
asyncBlock->queue = queue;
asyncBlock->context = nullptr;
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
    std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of XAsyncBlock*.
    HRESULT hr = XAsyncGetStatus(asyncBlock, false);
};

HRESULT hr = XblPresenceSetPresenceAsync(xboxLiveContext, true, nullptr, asyncBlock.get());
if (SUCCEEDED(hr))
{
    // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* because the callback will take over ownership.
    // If the call fails, std::unique_ptr will keep ownership and delete XAsyncBlock*.
    asyncBlock.release();
}
```

詳細については、以下を参照してください。

* [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)
* [XAsyncGetStatus](/reference/system/xasync/functions/xasyncgetstatus)
* [XblPresenceSetPresenceAsync](/reference/live/xsapi-c/presence_c/functions/xblpresencesetpresenceasync)

## リッチ プレゼンス ステータスの更新

#### フラット C API

```cpp theme={null}
XblPresenceRichPresenceIds ids{};
pal::strcpy(ids.scid, sizeof(ids.scid), scid);
ids.presenceId = "playingMap";
std::vector<const char*> tokenIds{ "CurrentMap" };
ids.presenceTokenIds = tokenIds.data();
ids.presenceTokenIdsCount = tokenIds.size();

HRESULT hr = XblPresenceSetPresenceAsync(xboxLiveContext, true, &ids, asyncBlock.get());
```

詳細については、以下を参照してください。

* [XblPresenceRichPresenceIds](/reference/live/xsapi-c/presence_c/structs/xblpresencerichpresenceids)
* [XblPresenceSetPresenceAsync](/reference/live/xsapi-c/presence_c/functions/xblpresencesetpresenceasync)


## Related topics

- [リッチ プレゼンスのサンプル コード](/ja-jp/services/xbox-services/community/presence/how-to/live-presence-howto-nav.md)
- [REST を介したユーザーのプレゼンスの更新](/ja-jp/services/xbox-services/community/presence/how-to/live-updating-presence-rest.md)
- [ユーザーのプレゼンスの取得](/ja-jp/services/xbox-services/community/presence/how-to/live-getting-a-users-presence.md)
- [XblPresenceStopTrackingUsers](/ja-jp/reference/live/xsapi-c/presence_c/functions/xblpresencestoptrackingusers.md)
- [ハウツー](/ja-jp/services/xbox-services/community/presence/how-to/index.md)
