타이틀 관리 도전 과제 가져오기
이 항목에서는 다음에 대해 설명합니다.
도전 과제 목록 가져오기
행 중인 타이틀의 도전 과제를 가져오려면 다음과 같이 XblAchievementsGetAchievementsForTitleIdAsync를 호출합니다.
XblAchievementsGetAchievementsForTitleIdAsync 호출
C++
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*.
XblAchievementsResultHandle resultHandle;
auto hr = XblAchievementsGetAchievementsForTitleIdResult(asyncBlock, &resultHandle);
if (SUCCEEDED(hr))
{
const XblAchievement* achievements = nullptr;
size_t achievementsCount = 0;
hr = XblAchievementsResultGetAchievements(resultHandle, &achievements, &achievementsCount);
for (size_t i = 0; i < achievementsCount; i++)
{
LogToScreen("Achievement %s: %s = %s",
achievements[i].id,
achievements[i].name,
(achievements[i].progressState == XblAchievementProgressState::Achieved) ? "Achieved" : "Not achieved");
}
XblAchievementsResultCloseHandle(resultHandle); // When you're done with the handle, close it.
achievements = nullptr; // Clear the array after calling XblAchievementsResultCloseHandle to the pointer to freed memory.
// Instead, you couldn't close the handle and store it. Then,
// if you needed to copy the handle, call XblAchievementsResultDuplicateHandle().
}
};
HRESULT hr = XblAchievementsGetAchievementsForTitleIdAsync(
xboxLiveContext,
xboxUserId,
titleId,
achievementType,
unlockedOnly,
orderBy,
skipItems,
maxItems,
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
- XblAchievement
- XblAchievementProgressState
- XblAchievementsGetAchievementsForTitleIdAsync
- XblAchievementsGetAchievementsForTitleIdResult
- XblAchievementsResultCloseHandle
- XblAchievementsResultDuplicateHandle
- XblAchievementsResultGetAchievements
도전 과제 결과의 다음 페이지 가져오기
도전 과제 페이지가 더 있을 수 있습니다. 확인하려면 XblAchievementsResultHasNext를 호출한 다음 XblAchievementsResultGetNextAsync을 호출합니다.
XblAchievementsResultHasNext 호출
플랫 C API
HRESULT hr = S_OK;
bool hasNext = false;
if (achievementsResult != nullptr)
{
hr = XblAchievementsResultHasNext(achievementsResult, &hasNext);
}
자세한 내용은 XblAchievementsResultHasNext를 참조하세요.
XblAchievementsResultGetNextAsync 호출
도전 과제의 다음 페이지를 가져오려면 다음과 같이 XblAchievementsResultGetNextAsync를 호출합니다.
C++
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*.
XblAchievementsResultHandle resultHandle;
auto hr = XblAchievementsResultGetNextResult(asyncBlock, &resultHandle);
if (SUCCEEDED(hr))
{
const XblAchievement* achievements = nullptr;
size_t achievementsCount = 0;
hr = XblAchievementsResultGetAchievements(resultHandle, &achievements, &achievementsCount);
for (size_t i = 0; i < achievementsCount; i++)
{
LogToScreen("Achievement %s: %s = %s",
achievements[i].id,
achievements[i].name,
(achievements[i].progressState == XblAchievementProgressState::Achieved) ? "Achieved" : "Not achieved");
}
XblAchievementsResultCloseHandle(resultHandle); // When you're done with the handle, close it.
achievements = nullptr; // Clear the array after calling XblAchievementsResultCloseHandle to the pointer to freed memory.
}
};
HRESULT hr = XblAchievementsResultGetNextAsync(
achievementsResult,
maxItems,
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
- XblAchievement
- XblAchievementProgressState
- XblAchievementsResultCloseHandle
- XblAchievementsResultGetAchievements
- XblAchievementsResultGetNextAsync
- XblAchievementsResultGetNextResult
단일 도전 과제 가져오기
단일 도전 과제를 가져오려면 다음과 같이 XblAchievementsGetAchievementAsync를 호출합니다.
플랫 C API
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*.
XblAchievementsResultHandle resultHandle;
auto hr = XblAchievementsGetAchievementResult(asyncBlock, &resultHandle);
if (SUCCEEDED(hr))
{
const XblAchievement* achievements = nullptr;
size_t achievementsCount = 0;
hr = XblAchievementsResultGetAchievements( resultHandle, &achievements, &achievementsCount );
// Use the achievements array to read the achievement data.
XblAchievementsResultCloseHandle(resultHandle); // When you're done with the handle, close it.
achievements = nullptr; // Clear the array after calling XblAchievementsResultCloseHandle to avoid the pointer to freed memory.
}
};
HRESULT hr = XblAchievementsGetAchievementAsync(
xboxLiveContext,
xboxUserId,
scid,
achievementId.c_str(),
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();
}
자세한 내용은 다음을 참조하십시오.