Share via


앱 및 추가 기능에 대한 제품 정보 가져오기

이 문서는 Windows.Services.Store 네임스페이스에 있는 StoreContext 클래스의 메서드를 사용하여 현재 앱 또는 일부 추가 기능에 대한 Store 관련 정보에 액세스하는 방법을 보여 줍니다.

전체 샘플 애플리케이션은 Store 샘플을 참조하세요.

참고

Windows.Services.Store 네임스페이스는 Windows 10 버전 1607에 도입되었으며 Windows 10 Anniversary Edition(10.0, 빌드 14393) 또는 Visual Studio의 최신 릴리스를 대상으로 하는 프로젝트에만 사용할 수 있습니다. 앱이 이전 버전의 Windows 10을 대상으로 하는 경우에는 Windows.Services.Store 네임스페이스 대신 Windows.ApplicationModel.Store 네임스페이스를 사용해야 합니다. 자세한 정보는 이 문서를 참조하십시오.

필수 조건

이러한 예제에는 다음과 같은 전제 조건이 있습니다.

  • Windows 10 Anniversary Edition(10.0, 빌드 14393) 이상 릴리스를 대상으로 하는 UWP(유니버설 Windows 플랫폼) 앱에 대한 Visual Studio 프로젝트입니다.
  • 파트너 센터에서 앱 제출을 생성하였으며 이 앱은 스토어에 게시되었습니다. 테스트하는 동안 Store에서 검색이 되지 않도록 앱을 구성할 수도 있습니다. 자세한 정보는 테스트 지침을 참조하세요.
  • 앱의 추가 기능에 대한 제품 정보를 가져오려면 파트너 센터에서 추가 기능을 생성해야 합니다.

이 예제의 코드는 다음을 가정합니다.

  • 코드는 workingProgressRing(이)라고 이름이 지정된 ProgressRingtextBlock(이)라고 이름이 지정된 TextBlock을 포함하는 페이지의 컨텍스트에서 실행됩니다. 이러한 개체는 각각 비동기 작업의 발생을 나타내며 출력 메시지를 표시하는 데 사용됩니다.
  • 코드 파일에는 Windows.Services.Store 네임스페이스에 대한 using 문이 있습니다.
  • 이 앱은 단일 사용자 앱으로, 해당 앱을 실행한 사용자의 컨텍스트에서만 실행됩니다. 자세한 정보는 앱 내 구매 및 평가판을 참조하세요.

참고

데스크톱 브리지를 사용하는 데스크톱 애플리케이션이 있는 경우, 이 예시에는 표시되지 않는 별도의 코드를 추가하여 StoreContext 개체를 구성해야 할 수도 있습니다. 자세한 정보는 데스크톱 브리지를 사용하는 데스크톱 애플리케이션에서 StoreContext 클래스 사용하기를 참조하세요.

현재 앱에 대한 정보 가져오기

현재 앱에 대한 Store 제품 정보를 가져오려면 GetStoreProductForCurrentAppAsync 메서드를 사용합니다 . 이 비동기 메서드는 가격 등의 정보를 가져오는 데 사용할 수 있는 StoreProduct 개체를 반환합니다.

private StoreContext context = null;

public async void GetAppInfo()
{
    if (context == null)
    {
        context = StoreContext.GetDefault();
        // If your app is a desktop app that uses the Desktop Bridge, you
        // may need additional code to configure the StoreContext object.
        // For more info, see https://aka.ms/storecontext-for-desktop.
    }

    // Get app store product details. Because this might take several moments,   
    // display a ProgressRing during the operation.
    workingProgressRing.IsActive = true;
    StoreProductResult queryResult = await context.GetStoreProductForCurrentAppAsync();
    workingProgressRing.IsActive = false;

    if (queryResult.Product == null)
    {
        // The Store catalog returned an unexpected result.
        textBlock.Text = "Something went wrong, and the product was not returned.";

        // Show additional error info if it is available.
        if (queryResult.ExtendedError != null)
        {
            textBlock.Text += $"\nExtendedError: {queryResult.ExtendedError.Message}";
        }

        return;
    }

    // Display the price of the app.
    textBlock.Text = $"The price of this app is: {queryResult.Product.Price.FormattedBasePrice}";
}

현재 앱과 연결된 알려진 Store ID가 있는 추가 기능에 대한 정보 가져오기

현재 앱과 연결된 추가 기능 및 Store ID를 이미 알고 있는 추가 기능에 대한 Microsoft Store 제품 정보를 가져오려면 GetStoreProductsAsync 메서드를 사용합니다. 이 비동기 메서드는 각 추가 기능을 나타내는 StoreProduct 개체 컬렉션을 반환합니다. Store ID 외에도 추가 기능의 형식을 식별하는 문자열 목록을 이 메서드에 전달해야 합니다. 지원되는 문자열 값 목록은 ProductKind 속성을 참조하세요.

참고

GetStoreProductsAsync 메서드는 현재 추가 기능을 구매할 수 있는지 여부에 상관 없이 앱과 연결된 지정된 추가 기능에 대한 제품 정보를 반환합니다. 현재 구매할 수 있는 현재 앱의 모든 추가 기능에 대한 정보를 검색하려면 다음 섹션에 설명된 대로 GetAssociatedStoreProductsAsync 메서드를 대신 사용합니다.

이 예제에서는 현재 앱과 연결된 지정된 Store ID를 가진 지속형 추가 기능에 대한 정보를 검색합니다.

private StoreContext context = null;

public async void GetProductInfo()
{
    if (context == null)
    {
        context = StoreContext.GetDefault();
        // If your app is a desktop app that uses the Desktop Bridge, you
        // may need additional code to configure the StoreContext object.
        // For more info, see https://aka.ms/storecontext-for-desktop.
    }

    // Specify the kinds of add-ons to retrieve.
    string[] productKinds = { "Durable" };
    List<String> filterList = new List<string>(productKinds);

    // Specify the Store IDs of the products to retrieve.
    string[] storeIds = new string[] { "9NBLGGH4TNMP", "9NBLGGH4TNMN" };

    workingProgressRing.IsActive = true;
    StoreProductQueryResult queryResult =
        await context.GetStoreProductsAsync(filterList, storeIds);
    workingProgressRing.IsActive = false;

    if (queryResult.ExtendedError != null)
    {
        // The user may be offline or there might be some other server failure.
        textBlock.Text = $"ExtendedError: {queryResult.ExtendedError.Message}";
        return;
    }

    foreach (KeyValuePair<string, StoreProduct> item in queryResult.Products)
    {
        // Access the Store info for the product.
        StoreProduct product = item.Value;

        // Use members of the product object to access info for the product...
    }
}

현재 앱에서 구매할 수 있는 추가 기능에 대한 정보 가져오기

현재 앱에서 현재 구매할 수 있는 추가 기능에 대한 Microsoft Store 제품 정보를 가져오려면 GetAssociatedStoreProductsAsync 메서드를 사용합니다. 이 비동기 메서드는 사용 가능한 각 추가 기능을 나타내는 StoreProduct 개체 컬렉션을 반환합니다. 이 메서드에 검색하려는 추가 기능의 형식을 식별하는 문자열 목록을 전달해야 합니다. 지원되는 문자열 값 목록은 ProductKind 속성을 참조하세요.

참고

앱에 구매할 수 있는 추가 기능이 많은 경우 GetAssociatedStoreProductsWithPagingAsync 메서드를 통해 페이징을 사용하여 추가 기능 결과를 반환할 수도 있습니다.

다음 예시에서는 현재 앱에서 구매할 수 있는 모든 지속형 추가 기능, Microsoft Store에서 관리하는 소모성 추가 기능 및 개발자가 관리하는 소모성 추가 기능에 대한 정보를 검색합니다.

private StoreContext context = null;

public async void GetAddOnInfo()
{
    if (context == null)
    {
        context = StoreContext.GetDefault();
        // If your app is a desktop app that uses the Desktop Bridge, you
        // may need additional code to configure the StoreContext object.
        // For more info, see https://aka.ms/storecontext-for-desktop.
    }

    // Specify the kinds of add-ons to retrieve.
    string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" };
    List<String> filterList = new List<string>(productKinds);

    workingProgressRing.IsActive = true;
    StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(filterList);
    workingProgressRing.IsActive = false;

    if (queryResult.ExtendedError != null)
    {
        // The user may be offline or there might be some other server failure.
        textBlock.Text = $"ExtendedError: {queryResult.ExtendedError.Message}";
        return;
    }

    foreach (KeyValuePair<string, StoreProduct> item in queryResult.Products)
    {
        // Access the Store product info for the add-on.
        StoreProduct product = item.Value;

        // Use members of the product object to access listing info for the add-on...
    }
}

사용자가 구매한 현재 앱의 추가 기능에 대한 정보 가져오기

현재 사용자가 구매한 추가 기능에 대한 Microsoft Store 제품 정보를 가져오려면 GetUserCollectionAsync 메서드를 사용합니다. 이 비동기 메서드는 각 추가 기능을 나타내는 StoreProduct 개체 컬렉션을 반환합니다. 이 메서드에 검색하려는 추가 기능의 형식을 식별하는 문자열 목록을 전달해야 합니다. 지원되는 문자열 값 목록은 ProductKind 속성을 참조하세요.

참고

앱에 많은 추가 기능이 있는 경우 GetUserCollectionWithPagingAsync 메서드를 통해 페이징을 사용하여 추가 기능 결과를 반환할 수도 있습니다.

다음의 예시에서는 지정한 Store ID를 가진 지속형 추가 기능에 대한 정보를 검색합니다.

private StoreContext context = null;

public async void GetUserCollection()
{
    if (context == null)
    {
        context = StoreContext.GetDefault();
        // If your app is a desktop app that uses the Desktop Bridge, you
        // may need additional code to configure the StoreContext object.
        // For more info, see https://aka.ms/storecontext-for-desktop.
    }

    // Specify the kinds of add-ons to retrieve.
    string[] productKinds = { "Durable" };
    List<String> filterList = new List<string>(productKinds);

    workingProgressRing.IsActive = true;
    StoreProductQueryResult queryResult = await context.GetUserCollectionAsync(filterList);
    workingProgressRing.IsActive = false;

    if (queryResult.ExtendedError != null)
    {
        // The user may be offline or there might be some other server failure.
        textBlock.Text = $"ExtendedError: {queryResult.ExtendedError.Message}";
        return;
    }

    foreach (KeyValuePair<string, StoreProduct> item in queryResult.Products)
    {
        StoreProduct product = item.Value;

        // Use members of the product object to access info for the product...
    }
}