首页 > 解决方案 > 即使我的用户已经订阅(沙盒),iap.subscribe(Skus[]) 机制也会返回 false

问题描述

我使用自动续订订阅的演示应用程序在我的应用程序上实现自动续订订阅。我可以登录并订阅,这将打开标准的 ios 订阅对话框。但是,下次我登录时,我从 Codenameone 调用 iap.isSubscribed() 机制,结果总是错误的(这是因为我在 testflight 环境中吗?)。当 isSubscribed 方法返回错误时,我将用户发送到具有订阅按钮的订阅页面,当按下此按钮时,我会收到一个对话框,通知我我已经订阅了。

我尝试使用模拟器以及实际的苹果 iphone6+,两者都没有为用户取回成功订阅的收据

@Override
public void initForm() {
    theme = UIManager.initFirstTheme("/theme");
    //create a new content container
    Container content = new Container();
    iap = Purchase.getInAppPurchase();
    // Pro only feature, uncomment if you have a pro subscription
    // Log.bindCrashProtection(true);
    // Define a receipt loader
    iap.setReceiptStore(createReceiptStore());
    /*
    The form needs to be split up into 3 parts 1 part for Successful subscriptions 
    1 part for paymens that have not been sucecssful yet 
    and  1 part for people who have not subscribed yet
     */
    if (!iap.isSubscribed(Skus)) {
        EMCDialogFactory.showMessageDialog("Subscription Failed", "Is Subscribed upon login: " + iap.isSubscribed(SKU_1_MONTH));
        content = createNonSubscribedHomeScreen();
    } else {
        EMCDialogFactory.showMessageDialog("Subscription Failed", "Is Subscribed upon login: " + iap.isSubscribed(SKU_1_MONTH));
        content = createSuccessfulHomeScreen();
    }

    setLayout(new BorderLayout());
    add(BorderLayout.CENTER, content);

}


/**
 * Creates a receipt loader to load receipts from our web service
 *
 * @return
 */
private ReceiptStore createReceiptStore() {
    //fetch all your receipts from the server to be used by the receipt store 
    listOfReceipts = fetchReceipts();
    return new ReceiptStore() {
        @Override
        public void fetchReceipts(SuccessCallback<Receipt[]> callback) {
            List<Receipt> out = new ArrayList<>();
            //loop through the receipts
            for (Receipt res : listOfReceipts) {
                //create a new receipt
                Receipt r = new Receipt();
                r.setTransactionId(res.getTransactionId());
                r.setPurchaseDate(res.getPurchaseDate());
                r.setQuantity(1);
                r.setSku(res.getSku());
                //check cancellation and expiry
                if (res.getCancellationDate() != null) {
                    r.setCancellationDate(res.getCancellationDate());
                }
                if (res.getExpiryDate() != null) {
                    r.setExpiryDate(res.getExpiryDate());
                }
                out.add(r);
            }
            callback.onSucess(out.toArray(new Receipt[out.size()]));
        }

        @Override
        public void submitReceipt(Receipt r, SuccessCallback<Boolean> callback) {
            submitTheReceipt(r, callback);
        }

    };
}

没有显示错误消息,它只是返回我未订阅的 false 并返回到我的订阅页面。但是,如果我再次按下我的订阅按钮,它会说我已经订阅了。

标签: javaiosmobilecodenameone

解决方案


推荐阅读