libgdx / gdx-pay

A libGDX cross-platform API for InApp purchasing.
Apache License 2.0
225 stars 83 forks source link

Crash in IOS when offers are all CONSUMABLE #41

Closed panhaozi closed 9 years ago

panhaozi commented 9 years ago

The crach log is below: tmp145559b6 I guess a NPE is thrown.

panhaozi commented 9 years ago

My environment: libgdx 1.5.6, gdx-pay 0.5.0-SNAPSHOT

noblemaster commented 9 years ago

Might be related to the purchase configuration you have setup. Can you post your configuration of offers/etc.?

panhaozi commented 9 years ago
            if(PurchaseSystem.hasManager())
            {
                Gdx.app.log("iap", "hasManager"); 
                PurchaseManagerConfig config = new PurchaseManagerConfig();         
                config.addOffer(new Offer().setIdentifier("30days_menbership").setType(OfferType.CONSUMABLE));
                config.addOffer(new Offer().setIdentifier("100crystals").setType(OfferType.CONSUMABLE));
                PurchaseSystem.install(new PurchaseObserver()
                {
                    @Override
                    public void handleRestoreError(Throwable arg0)
                    {
                        Gdx.app.log("iap", "handleRestoreError");
                    }

                    @Override
                    public void handleRestore(Transaction[] arg0)
                    {
                        Gdx.app.log("iap", "handleRestore");
                        PurchaseSystem.purchase("100crystals");
                    }

                    @Override
                    public void handlePurchaseError(Throwable arg0)
                    {
                        Gdx.app.log("iap", "handlePurchaseError");
                    }

                    @Override
                    public void handlePurchaseCanceled()
                    {
                        Gdx.app.log("iap", "handlePurchaseCanceled");
                    }

                    @Override
                    public void handlePurchase(Transaction arg0)
                    {
                        Gdx.app.log("iap", "handlePurchase");
                    }

                    @Override
                    public void handleInstallError(Throwable arg0)
                    {
                        Gdx.app.log("iap", "handleInstallError");
                    }

                    @Override
                    public void handleInstall()
                    {
                        Gdx.app.log("iap", "handleInstall");
                        PurchaseSystem.purchaseRestore();
                    }
                }, config);
            }
            else
                Gdx.app.log("iap", "noManager");
noblemaster commented 9 years ago

This might be a problem: PurchaseSystem.purchase("100crystals") should not be in handleRestore(...). This method is called from the actual store and making a call to a purchase might pose problems.

PurchaseSystem.purchaseRestore(): this should not go into handleInstall(). This method will ask for a username/password for some stores and cause problems.

panhaozi commented 9 years ago

Yeah, you were right.Thax