No notification of failure when calling purchaseProduct without internet connection


On iOS, if I call InAppPurchases::purchaseProduct while the internet connection is off, the purchase obviously fails but the InAppPurchases::Listener gets no notification. Here is a suggested change to requestDidFailWithError (not sure why it is not called on the message thread in that case, but I had to add a callAsync).

        } else if (auto productRequest = getAs<SKProductsRequest> (request)) {
            for (auto i = 0; i < pendingProductInfoRequests.size(); ++i)
                auto& pendingRequest = *pendingProductInfoRequests[i];

                if (pendingRequest.request.get() == productRequest)
                    MessageManager::callAsync([this]() {
               ([&] (Listener& l) { l.purchasesListRestored ({}, false, NEEDS_TRANS ("Cannot connect to the App Store")); });}
                    pendingProductInfoRequests.remove (i);

(this code just mirrors the code that handles SKReceiptRefreshRequest errors).

UPDATE: it would probably be better to call l.productPurchaseFinished instead of purchasesListRestored when pendingRequest.type == PendingProductInfoRequest::Type::purchase.

Thanks for raising this issue. I’ve pushed a fix here:

1 Like