CurrentAppSimulator.RequestProductPurchaseAsync purchasing simulation

烈酒焚心 提交于 2019-12-03 04:02:20

Make sure the app LicenseInformation.IsTrial is false, otherwise it won't work. In-app product purchases require that the app not be in trial. In a published app, the user would see an error stating that you can't do in-app product purchases under trial license. The simulator doesn't show this warning in the in-app purchase simulation dialog during testing.

You can either modify the initial state of the simulation (see the samples for how to do that) or call RequestAppPurchaseAsync(false) during the simulation run to get a full license for the app, then try the product purchase.

We experienced and solved a similar problem. Using CurrentAppSimulator worked fine, but bringing up the real purchasing UI with CurrentApp did not.

In a production setting await CurrentApp.RequestProductPurchaseAsync(string,bool) seemed to never return (more specifically, it only returns once after the user has logged in -- subsequent calls did not return).

Additionally, after we tried to bring up the purchasing UI in our app, other applications using the purchasing UI had the same problem -- UI never shows.

Here is the problem code:

    private async void CommandInvokedHandler(IUICommand command)
    {
        switch (command.Label)
        {
            case "Continue":

                licenseInformation = CurrentApp.LicenseInformation;

                if (!licenseInformation.ProductLicenses[Notes.ProductName].IsActive)
                {
                    try
                    {
                        await CurrentApp.RequestProductPurchaseAsync(Notes.ProductName, false);
                        // The code never steps over
                    }

The somewhat-obvious problem with the code above is that the request to bring up the in-app purchase UI is made from within a modal dialog box command handler. The request hangs -- never returns. The not-so-obvious part is that it also blocks all subsequent requests from our application and every other application (until the user's session is restarted).

Upon moving the "try" block out of the command handler, and ensuring that there are no modal UI calls contesting the purchase request, purchasing worked without issue.

EDIT: You should restart (or re-login) to test this. Once the purchasing UI breaks, it will not show until you restart or re-login.

There is a small nuance to follow: to be able to purchase anything using CurrentAppSimulator one needs to call CurrentAppSimulator.RequestAppPurchaseAsync before making any purchase requests. After the operation returned by the call is done, you can successfully call CurrentAppSimulator.RequestProductPurchaseAsync (unless the IsTrial value in LicenseInformation element is set to false in the xml).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!