在Corona SDK中,store.purchase()总是在所有情况下超时/返回?

时间:2013-10-28 23:46:31

标签: corona

在所有情况下,store.purchase()总是会超时/返回吗?

那我可以确信我可以将一个微调器留在我的模态对话框中,等待来自此调用的响应吗?

(在http://docs.coronalabs.com/daily/api/library/store/purchase.html#store.purchase)的文档中并没有真正说明这一点

2 个答案:

答案 0 :(得分:3)

是的,确实如此。使用store.init( [storeName,] listener )启动商店时,您可以为商家指定商店名称和回调函数,例如store.init("apple", transactionCallback)。在此回调函数中,您可以检查某些事务状态。

local function transactionCallback( event )
    local transaction = event.transaction
    print("EVENT:PHASE = " .. transaction.state)

    if transaction.state == "purchased" then
        print("Transaction succuessful!")
        print("productIdentifier", transaction.productIdentifier)
        print("receipt", transaction.receipt)
        print("signature", transaction.signature)
        print("transactionIdentifier", transaction.identifier)
        print("date", transaction.date)
    elseif  transaction.state == "restored" then
        print("Transaction restored (from previous session)")
        print("signature", transaction.signature)        
        print("productIdentifier", transaction.productIdentifier)
        print("receipt", transaction.receipt)
        print("transactionIdentifier", transaction.identifier)
        print("date", transaction.date)
        print("originalReceipt", transaction.originalReceipt)
        print("originalTransactionIdentifier", transaction.originalIdentifier)
        print("originalDate", transaction.originalDate)
    elseif transaction.state == "cancelled" then
        print("User cancelled transaction")
    elseif transaction.state == "failed" then
        print("Transaction failed, type:", transaction.errorType, transaction.errorString)
    else
        print("unknown event")
    end
end

答案 1 :(得分:0)

是的,但是如果它感觉到某种类型的互联网连接(即使是坏的),它会保持对话直到它收到响应并考虑在移动互联网上玩的玩家通常连接不良。如果在合理的时间内未收到回复,您可能需要插入取消过程的电晕计时器并通知对话用户。