Share via

Error when using DownloadProfileMetadataAsync to download ESim Profile CardGeneralFailure

Yaguang Ruan 20 Reputation points
2024-11-07T02:04:33.9133333+00:00

使用以下代码去下载EsimProfile,打印的result是

2024-11-07 09:41:57.3182 INFO +++MainPage+++ +++ download failedCardGeneralFailure

public async Task<ESimDownloadProfileMetadataResult> DownloadEsimProfileMetadataAsync(string activationCode, ESim esim)
{


    IAsyncOperation<ESimDownloadProfileMetadataResult> asyncOperation = esim.DownloadProfileMetadataAsync(activationCode);


    ESimDownloadProfileMetadataResult result = await asyncOperation.AsTask();

    if (result.Result.Status == ESimOperationStatus.Success)
    {
        string operatorName = result.ProfileMetadata.ProviderName;

        Logger.Log("+++ download success , start install profile" + operatorName);

        await InstallESimProfileAsync(result.ProfileMetadata);

    }
    else
    {
        Logger.Log("+++ download failed" + result.Result.Status);
    }

    return result;
}


public async Task InstallESimProfileAsync(ESimProfileMetadata esimProfileMetadata)
{

    // Call the asynchronous installation method
    IAsyncOperationWithProgress<ESimOperationResult, ESimProfileInstallProgress> asyncOp = esimProfileMetadata.ConfirmInstallAsync();

    try
    {
        // Wait for the operation to complete
        ESimOperationResult result = await asyncOp.AsTask();

        // Check the operation result
        if (result.Status == ESimOperationStatus.Success)
        {
            Logger.Log("eSIM profile installed successfully.");
        }
        else
        {

            Logger.Log($"Failed to install eSIM profile. Error: {result.Status}");
        }
    }
    catch (Exception ex)
    {
        // Handle exceptions in the asynchronous operation
        Logger.Log($"An error occurred: {ex.Message}");
    }
}


Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.