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

# 사용자의 Presence 가져오기

> XblPresenceGetPresenceAsync를 호출하여 XBOX Live 사용자의 Presence 레코드를 가져오고 반환된 온라인 상태 데이터를 읽는 XSAPI flat C 예제입니다.

이 항목에서는 사용자의 Presence를 가져오기 위한 예제 코드를 제공합니다.​

## 단일 사용자의 Presence 가져오기

#### Flat 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 = XblPresenceGetPresenceResult(asyncBlock, &state.presenceRecord);

    // Be sure to call XblPresenceRecordCloseHandle when the presence record is no longer needed.
};

HRESULT hr = XblPresenceGetPresenceAsync(xboxLiveContext, xboxUserId, 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)
* [XblPresenceGetPresenceAsync](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceasync)
* [XblPresenceGetPresenceResult](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceresult)
* [XblPresenceRecordCloseHandle](/reference/live/xsapi-c/presence_c/functions/xblpresencerecordclosehandle)

## 여러 사용자의 Presence 문자열 가져오기

#### Flat 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*.
    size_t resultCount{ 0 };
    HRESULT hr = XblPresenceGetPresenceForMultipleUsersResultCount(asyncBlock, &resultCount);

    if (SUCCEEDED(hr) && resultCount > 0)
    {
        std::vector<XblPresenceRecordHandle> handles(resultCount, nullptr);
        hr = XblPresenceGetPresenceForMultipleUsersResult(asyncBlock, handles.data(), resultCount);

        // Be sure to call XblPresenceRecordCloseHandle for each presence record when they're
        // no longer needed.
    }
};

std::vector<uint64_t> xuids{ 123, 456 };

// Filter results to only online users.
XblPresenceQueryFilters filters{};
filters.onlineOnly = true;

HRESULT hr = XblPresenceGetPresenceForMultipleUsersAsync(xboxLiveContext, xuids.data(), xuids.size(), &filters, 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)
* [XblPresenceGetPresenceForMultipleUsersAsync](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceformultipleusersasync)
* [XblPresenceGetPresenceForMultipleUsersResult](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceformultipleusersresult)
* [XblPresenceGetPresenceForMultipleUsersResultCount](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceformultipleusersresultcount)
* [XblPresenceQueryFilters](/reference/live/xsapi-c/presence_c/structs/xblpresencequeryfilters)
* [XblPresenceRecordCloseHandle](/reference/live/xsapi-c/presence_c/functions/xblpresencerecordclosehandle)

## 소셜 그룹에서 사용자의 Presence 가져오기

#### Flat 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*.
    size_t resultCount{ 0 };
    HRESULT hr = XblPresenceGetPresenceForSocialGroupResultCount(asyncBlock, &resultCount);

    if (SUCCEEDED(hr) && resultCount > 0)
    {
        std::vector<XblPresenceRecordHandle> handles(resultCount, nullptr);
        hr = XblPresenceGetPresenceForSocialGroupResult(asyncBlock, handles.data(), resultCount);

        // Be sure to call XblPresenceRecordCloseHandle for each presence record when they're
        // no longer needed.
    }

};

HRESULT hr = XblPresenceGetPresenceForSocialGroupAsync(xboxLiveContext, "Favorites", nullptr, 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)
* [XblPresenceGetPresenceForSocialGroupAsync](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceforsocialgroupasync)
* [XblPresenceGetPresenceForSocialGroupResult](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceforsocialgroupresult)
* [XblPresenceGetPresenceForSocialGroupResultCount](/reference/live/xsapi-c/presence_c/functions/xblpresencegetpresenceforsocialgroupresultcount)
* [XblPresenceRecordCloseHandle](/reference/live/xsapi-c/presence_c/functions/xblpresencerecordclosehandle)

## 사용자의 Presence 표시하기

#### Flat C API

```cpp theme={null}
const XblPresenceDeviceRecord* deviceRecords{ nullptr };
size_t deviceRecordsCount{ 0 };
HRESULT hr = XblPresenceRecordGetDeviceRecords(state.presenceRecord, &deviceRecords, &deviceRecordsCount);

for (auto i = 0u; i < deviceRecordsCount; ++i)
{
    auto& deviceRecord{ deviceRecords[i] };
    LogToFile("Got XblDeviceRecord with device type %u and %u title records", deviceRecord.deviceType, deviceRecord.titleRecordsCount);

    for (auto j = 0u; j < deviceRecord.titleRecordsCount; ++j)
    {
        auto& titleRecord{ deviceRecord.titleRecords[j] };
        // Display the Rich Presence string.
        LogToFile("Rich presence string for titleId %u: %s", titleRecord.titleId, titleRecord.richPresenceString);
    }
}
```

자세한 내용은 다음을 참조하세요.

* [XblPresenceDeviceRecord](/reference/live/xsapi-c/presence_c/structs/xblpresencedevicerecord)
* [XblPresenceRecordGetDeviceRecords](/reference/live/xsapi-c/presence_c/functions/xblpresencerecordgetdevicerecords)


## Related topics

- [Rich Presence 예제 코드](/ko/services/xbox-services/community/presence/how-to/live-presence-howto-nav.md)
- [방법](/ko/services/xbox-services/community/presence/how-to/index.md)
- [소셜 관계 가져오기](/ko/services/xbox-services/community/people-system/how-to/live-getting-a-social-relationship.md)
- [이벤트 기반 통계 가져오기](/ko/services/xbox-services/player-data/stats-leaderboards/event-based/how-to/live-getting-eb-stat.md)
- [통계와 업적](/ko/build/steam-porting-guide/features/stats-and-achievements.md)
